Chapter 22. Customizing Entities

One of the most powerful features of Microsoft Dynamics CRM is that you can customize (or configure) almost all entities, such as Account, Contact, and Opportunity entities, as well as add new custom entities to suit your needs.

Navigate to the main entity customization screen by going to Settings > Customizations, and you see that you can customize entities in several ways (see Figure 22.1).

Image

FIGURE 22.1 Customization interface.

The customization screen presents the following options, which are all covered in this chapter:

Image Customize the System

Image Publishers

Image Solutions

Image Developer Resources

Image Themes

You can customize existing entities or create new entities. In CRM 2016, you can customize an entity without going to the Settings area; instead, you can just go to any entity and click ... > Customize Entity, as shown in Figure 22.2.

Image

FIGURE 22.2 Customizing an entity.

Alternatively, you can open a form for an entity and click ... > Form, as shown in Figure 22.3, to start making changes.

Image

FIGURE 22.3 Customizing a form.

Customization Principles

The most basic principle with regard to customization is that Microsoft Dynamics CRM is built according to an n-tier model, with the user interface layers (web client, Outlook client, phone client, and tablet client) on top, the application layer in the middle, and the database layer (SQL Server) on the bottom. To avoid layer conflict and have a properly managed n-tier application model, you should always make the customizations following the principles described in this chapter.

Image Refer to the section “Solution Concepts,” later in this chapter, to review some basic principles related to customizations.


Note

If you are an expert SQL database administrator or developer, you might be tempted to create database triggers or stored procedures or change the database schema. However, I strongly recommend that you not touch the database directly in any situation. Doing so is considered an unsupported customization and might cause the application to break or fail.


Customization can be characterized in two ways in Microsoft Dynamics CRM: supported and unsupported. This chapter covers only supported customizations that follow Microsoft best practices and that generally do not fail when the product is upgraded. Unsupported customizations might perform any function, but they fall outside the range of Microsoft’s testing when considering upgrades, database schema changes, and support rollups. The following results can occur with unsupported customizations:

Image Service packs might fail, break, or not install.

Image Upgrades to the product might cause unexpected results or fail.

Image The application or database might become unstable and fail to work.

The Dynamics CRM Entity Model

Much as in an XML document, all objects in Microsoft Dynamics CRM are treated as entities or attributes. Account, Contact, Activity, and so on are entities in the CRM system, and every entity has related attributes and relationships, which are also called fields. For example, Figure 22.4 shows the fields (such as Account Name) for the Account entity.

Image

FIGURE 22.4 Fields for the Account entity.


Note

You can rename the existing system entities if the default names don’t work for your business. For example, lot of companies rename the Account entity Company or Organization. If you do this, keep in mind that only the name of the entity that is displayed is renamed; the logical name (in this example Account) remains the same.


Fields

Fields can be of the following data types:

Image Single line of text (nvarchar type)—This type is used for small texts or strings. It can have a maximum of 4,000 characters.

Image Option set (picklist type)—This type is used for drop-downs or combo boxes, with a limited set of fixed options. Option sets were called picklists in earlier versions of Dynamics CRM.


Note

Because an option set can display only simple, nondynamic options, you might want to use a new custom entity if you need something that is more dynamic or complex than the options provided, and use a lookup control type instead.



Tip

You can reuse an option set on more than one entity by using global option sets.


Image Two options (bit type)—This type is used for Boolean values such as yes or no.

Image Image (image type)—This type is used to store an image (maximum 5120KB size). You can have a maximum of one image type field per entity, and you cannot add a field of this type to system entities.

Image Whole number (int type)—This type is used for numbers that can be any of these formats:

Image None—Sets the min and maximum values.

Image Duration—Presents a drop-down list so the user can select X Minutes, X Hours, or X Days. Hours and days can also be entered using decimals—for example, x.x hours or x.x days.

Image Time Zone—Shows a drop-down list with the different time zones the user can select, such as (GMT -08:00) Pacific time.

Image Language—Shows a drop-down with the different languages installed by the system. The data will be stored using the language code; for example, English in United States is1033. For a complete table of language codes, visit https://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx.

Image Floating-point number (float type)—This type is used for floating-point decimal numbers.

Image Decimal number (decimal type)—This type is used for numbers with decimals.

Image Currency (money type)—This type is used for amounts.

Image Multiple lines of text (ntext type)—This type is used for large texts or strings with a maximum length of 1,048,576.

Image Date and time (datetime type)—This type is used for dates and times, which can have the following behaviors:

Image User Local—This option, used by all the previous version of Dynamics CRM, shows the value of the date and time in the user’s local time zone.

Image Date Only—This option, which is new to Dynamics CRM 2016, shows only the date, regardless of the user time zone configuration.

Image Time Zone Independent—This option, which is new to Dynamics CRM 2016, shows the date and time field without doing any time zone conversion, so if the original user entered a date with the time 7:00 AM any user, regardless of location or configured time zone, will see 7:00 AM. This is a great new addition. You can use it, for example, for an entity called Course when you want to enter the value for the course start time in New York; then if you have a customer rep in California, he will be able to see that date and time in New York time and not converted to the California time zone, as used to happen in older versions of Dynamics CRM.

Image Lookup (lookup type)—This type is used to look up other entities’ relationships.

Entities are associated with other entities via a customization referred to as a relationship.

Calculated Fields

A new addition to CRM is calculated fields, which you can use to perform automated calculations that you used to have to do using JavaScript or other code. The following data types supports calculated fields:

Image Single line of text

Image Option set

Image Single

Image Two options

Image Whole number

Image Decimal number

Image Currency

Image Date and time

When you select Calculated from the Field Type drop-down, a new Edit button appears, as shown in Figure 22.5.

Image

FIGURE 22.5 Adding a calculated field.


Note

Before clicking the Edit button, you must enter the display name and name of the field because clicking the Edit button creates the field as if clicked Save.


When the field is created, you see the calculated field editor (see Figure 22.6), in which you can configure conditions and actions.

Image

FIGURE 22.6 Calculated field editor.

The calculated field editor has IntelliSense, so it is very easy to find the fields. For example, for a single line of text you can use the CONCAT function to concatenate fields with fixed text.

You can then use your calculated fields in forms and views. When you use calculated fields on forms, they are always displayed as read only, and the calculation happens as soon as you save the record.

These are the functions you can use in the calculated field editor:

Image ADDHOURS

Image ADDDAYS

Image ADDWEEKS

Image ADDMONTHS

Image ADDYEARS

Image SUBTRACTHOURS

Image SUBTRACTDAYS

Image SUBTRACTWEEKS

Image SUBTRACTMONTHS

Image SUBTRACTYEARS

Image DIFFINDAYS

Image DIFFINHOURS

Image DIFFINMINUTES

Image DIFFINMONTHS

Image DIFFINWEEKS

Image DIFFINYEARS

Image CONCAT

Image TRIMLEFT

Image TRIMRIGHT

Rollup Fields

Rollup fields allow you to perform automated calculations based on the related entity records. To do this in previous versions of Dynamics CRM, you had to use JavaScript or other code. The following data types support rollup fields:

Image Whole number

Image Decimal number

Image Currency

Image Date and time

With a rollup field, you could, for example, show the count of contacts related to an account, using a whole number field.

When you select Rollup from the Field Type drop-down, a new Edit button appears, as shown in Figure 22.7.

Image

FIGURE 22.7 Adding a rollup field.


Note

Before clicking the Edit button, you must enter the display name and name of the field because clicking the Edit button creates the field as if clicked Save.


When the field is created, you see the rollup field editor (see Figure 22.8), which you can use to configure the source entity, the related entity, the filters with conditions, and the aggregation method, which can be any of the following:

Image SUM

Image MAX

Image MIN

Image COUNT

Image AVG

Image

FIGURE 22.8 Rollup field editor.


Note

For each rollup field, two system jobs are created. One of them will run every 5 minutes, and the other will be a massive update that runs every 12 hours to update the values of all the records that use the rollup field.


For each rollup field you create, three fields are created in CRM: one with the calculated value, another with the date of the last update, and another to see the state of the field (see Figure 22.9).

Image

FIGURE 22.9 Rollup field available for use.

Like calculated fields, rollup fields are displayed as read-only in forms, so users can’t change the calculated value. However, a rollup field has a calculator icon the user can use to force the calculation if the system job didn’t execute yet.

By clicking the refresh button inside a rollup field, you can force the evaluation of the data. Then, after you save the record, you see the other two related fields updated.

Keys

You can define your own alternate keys on entities. When creating a new alternate key, you can define one or more fields. For example, you can create a key for the Account Number field of the Account entity. By creating a key like, you can prevent users from creating accounts with duplicate account numbers. Figure 22.10 shows the custom key options.

Image

FIGURE 22.10 Custom key options.


Note

Depending on how much data you have, a custom key you create might take some time to become active.


You can then use the alternate keys you create in the update and upsert operations. Alternate keys are used for integration jobs, providing a key reference that allows for updates to occur. See the Dynamics CRM software development kit (SDK) for more information about how to work with alternate keys.

Relationships

Not to be confused with relationships/connections at the interface level, relationships at the schema level are programmatic. Even so, relationships are very user friendly; you don’t need to be a database system administration expert to use and configure relationships between entities.

Microsoft Dynamics CRM supports the following relationships:

Image 1:N relationships (one to many)

Image N:1 relationships (many to one)

Image N:N relationships (many to many)

You can add as many relationships as you want, and you can also add more than one relationship to the same entity. For example, you can have a custom entity called Customer and add two fields called Primary Contact and Secondary Contact, both related to the entity Contact.

Finally, another feature to relationships is the ability to relate an entity to itself, which is referred as self-referential. Using this type of relationship, you can use any type of relationship (1:N, N:1, or N:N) to relate an entity to itself.

1:N Relationships

Figure 22.11 shows the window where you can create a new 1:N relationship. With this type of relationship, the primary entity is the one you are customizing. For example, if you are working with the Account entity, you could use a 1:N relationship to specify the primary account for another entity, such as Contact, for which the custom field defined by this relationship will contain only one account.

Image

FIGURE 22.11 Creating a new 1:N relationship.

N:1 Relationships

With an N:1 relationship, the primary entity is the one you select. Therefore, the entity you are customizing is the related entity. For example, if you want a Contact entity to have multiple Account entities associated with it, you apply an N:1 relationship to the Account entity.

N:N Relationships

With an N:N relationship, there is not one primary entity and another secondary or related entity; rather, they both act as both types. For example, you might want to have one Contact entity related to many Account entities or one Account related to many Contact entities. You might, for instance, have a Contact with a new person who works for two companies, and each company might have many Contact entities apart from this one.

Relationship Behavior

For N:1 and 1:N relationships, there are settings for the relationship behavior, called cascading rules, that apply to the following operations:

Image Assign

Image Share

Image Unshare

Image Reparent

Image Delete

Image Merge

The Type of Behavior drop-down in the relationship cascading rules contains four options:

Image Parental

Image Referential

Image Referential, Restrict Delete

Image Configurable Cascading

The first three options are templates, and the last option, Configurable Cascading, allows you to configure the cascading manually for each operation.

The first four operations—Assign, Share, Unshare, and Reparent—all have the same cascading types:

Image Cascade All—This option affects the current entity record and its related entity records. So the operation is performed on both entities.

Image Cascade Active—This option affects the current entity record and its related entity records that have a status of Active.

Image Cascade User-Owned—This option affects the current entity record and its related entity records that are owned by the user who is performing the operation only.

Image Cascade None—This option affects only the current entity and not the related entity records.

The Delete operation has different cascading options, as follows:

Image Cascade All—This option is the same as explained above except that if you have a 1:N relationship between Account and Contact and you have 1 account record with 10 contacts related, when you delete the account, all 10 contacts are also deleted.

Image Remove Link—With this option, you can remove a link. Using the preceding example, if you delete the account record, the contacts aren’t deleted, but the link between the contacts and the account are removed.

Image Restrict—With this option, only when the account doesn’t have any related records can it be deleted. Using the earlier example, you won’t be able to delete the account until you delete all the related contacts manually first.

The Merge operation changes between Cascade None and Cascade All, depending on the primary entity selected, and you can’t modified it.

Messages

Messages display information to the user based on a variety of actions. Users can customize these messages to display richer or different information, if desired.


Note

Remember to manually update the messages if you have renamed a system entity because the messages aren’t updated automatically.


Basic Customizations

Basic customizations are customizations to Microsoft Dynamics CRM that don’t require any knowledge of programming or database design and configuration. Basic customizations include showing and hiding controls on a form and hiding or showing columns in a view.


Note

For conditional showing and hiding of controls, you can use business rules, which are explained later in this chapter, in the section “Business Rules.”


To make this type of customization, go to the entity you want to customize and go to the Forms or Views node in the left navigation area, as shown in Figure 22.12. The following sections describe the particular form customizations and view customizations that are possible.

Image

FIGURE 22.12 Form and view customizations.

Form Customizations

Microsoft Dynamics CRM 2016 supports more than one type of form. A form can be any of the following types:

Image Main

Image Mobile - Express

Image Quick View

Image Quick Create

Image Card

Image Main-interactive Experience

You can create new form designs and layouts, as well as Quick Create and Quick View forms. Quick Create forms allow you to create records quickly and with fewer fields on the form—without leaving the entity with which you’re working. Quick View forms show the data of the parent record on a child record form but in read-only mode.

Main Forms

The following sections explain how you can customize the Main forms, using features in Microsoft Dynamics CRM 2016.

Adding, Removing, or Moving Tabs

The tabs in CRM 2016 behave differently than in earlier versions. You can now navigate to the tabs by using the tab navigator (see Figure 22.13), and the navigation bar has links pointing to bookmarks in the form. You can add tabs with one, two, or three columns, and each column can have one or more sections. Figure 22.14 shows a form with multiple tabs and different column options.

Image

FIGURE 22.13 New tab navigator for the Account entity Main form.

Image

FIGURE 22.14 New custom tabs named Tab.

Every time you add a new tab, you also get at least one new section inside the new tab.

Adding, Removing, or Moving Sections

Sections are used to group controls for related fields. The sections must be within a tab. To add a new section, click the buttons on the Insert tab under the Section group. When you double-click the new added section, the Section Properties dialog appears (see Figure 22.15).

Image

FIGURE 22.15 Section Properties dialog.

You can choose whether a label displays the section name, and you can also specify the width of the field area (refer to Figure 22.15). You also have some layout options such as the number of columns to display data as shown in Figure 22.16.

Image

FIGURE 22.16 Formatting section properties.


Tip

To move a section from one tab to another, just drag and drop the section.



Note

If the predefined layouts don’t match your requirements, consider adding a web resource (type HTML) or developing a custom page in ASP.NET and adding an IFRAME to display your custom page inside the form, as detailed in the “Adding, Removing, or Moving IFRAMEs” section, later in this chapter.


Adding, Removing, or Moving Fields

Fields are used to display the entity fields with input controls. If you have created a custom field, as described earlier in this chapter, you need to add an input control for that field to allow users to enter the values. To add a field to the form, just select the field from the Field Explorer list and drag and drop it to the section or tab where you want it.


Note

To avoid adding duplicate fields, the Field Explorer by default shows only the available fields that have not already been added to any tab or section in the form. If you uncheck the Only Show Unused Fields check box, you always see all fields, and you can add the same field more than once on the same form—but only in different sections.


You can also select the section where you want to place a field and then go to the Field Explorer and double-click the field you want; it is then added to the selected section.


Tip

You can drag and drop to move a field to any place inside a section. You can also add fields to the header or footer of a form, which are always shown, regardless of the tab the user has selected. Be sure to click the Header button that is on the Home tab of the ribbon if you want to be able to add fields on the header. You can customize the navigation links when you click the Navigation button on the ribbon.


Adding, Removing, or Moving IFRAMEs

You can use IFRAMEs to display custom applications or pages inside a form. Doing so is extremely helpful when you want to show content from external applications or when you need to use advanced input/output controls that are not included in the CRM controls toolset. Examples include a complex grid, a picture control, or a movie control. When you click the IFRAME button, you get the Add an IFRAME dialog, shown in Figure 22.17, which requires the name for the IFRAME as well as the URL of your application.

Image

FIGURE 22.17 Adding an IFRAME.

For example, say that you want to enter Website in the Name field and www.microsoft.com/silverlight/iis-smooth-streaming/demo/ in the URL field. When adding the IFRAME with these settings and the default values, you then see the IFRAME inserted in the form.

Most of the time, you want an IFRAME to expand vertically to fill the entire form. To make that happen, select the IFRAME, click Change Properties, and then, on the Formatting tab, in the Row Layout section, check the Automatically Expand to Use Available Space check box.

In the Scrolling section, you can choose whether you want to have the IFRAME show the scrollbars (vertical and horizontal) as necessary (which is the default value), always, or never. Finally, you can specify whether you want to show a border around the IFRAME by clicking the Display Border property in the Border section.

Click the OK button when you’re ready to accept your changes. You do not see the IFRAME expand on the form in design mode, but you will see it expanded when you run the application.

In the URL used in this example, there are Silverlight controls in the page contents to be displayed in an IFRAME, and you won’t see the page render properly inside the IFRAME.

Changing Default IFRAME Properties

When you first set an IFRAME URL, you may get a Page Can’t Be Loaded error message or a message about unexpected results (for example, No Silverlight Content Displayed). This behavior is normal. It is the default behavior because of the protection that is set by default on the IFRAME properties to prevent the external pages from executing JavaScript codes or ActiveX controls that might perform unintended operations on the CRM application, such as closing the form unexpectedly without allowing CRM to control the window and save the data properly. However, you can change this security setting to have a page load correctly if you’re sure there will not be a problem. To do so, select the IFRAME and click Change Properties. In the Security section of the dialog, uncheck the Restrict Cross-Frame Scripting, Where Supported check box (see Figure 22.18).

Image

FIGURE 22.18 Removing the cross-frame scripting protection.

Click OK to close the dialog and test it by opening an Account record form. You now see the page load properly, without any warnings (see Figure 22.19).

Image

FIGURE 22.19 IFRAME test with active content displayed.

This example uses a web page URL that shows the same content regardless of when and where in CRM it is shown. Most of the time, however, you will want to use an IFRAME to show different content depending on the entity and record instance being displayed. For instance, you might want to show the company web page in an IFRAME when working with accounts and then show an individual’s picture in the IFRAME when working with contacts. In that case, you need to create either a web resource (type HTML) or a custom ASP.NET application and read the globally unique identifier (GUID) of the record that will be passed to the web application. This is accomplished by checking the Pass Record Object-Type Code and Unique Identifier as Parameters check box.

Changing Properties of a Tab, Section, Field, or IFRAME

Here you can access the properties of the section you are positioning. For example, if you select a tab, you have access to the tab properties. If you select a field, the properties are related to the field selected.

Adding a Bing Map to Multiple Forms

In CRM 2016, you can add a Bing map control to system entities that have a composite address field. The following entities can display Bing maps on forms:

Image Account

Image Contact

Image Lead

Image User

Image Quote

Image Order

Image Invoice

Image Competitor

You need to sign in to the Bing Maps portal and create an API key to use for On-Premises deployment, but you do not need to do any additional configuration to use it in Microsoft Dynamics CRM Online. When you put a Bing Maps component on a form, select the address that will be displayed.

You can create multiple forms for an entity in CRM 2016. To do so, you can open an existing form and click Save As to create a copy or you can click New and select the type of form you want to create. You can assign security roles to a form to control access to it; to do so, click the Enable Security Roles button at the top of the command bar.


Note

You can only have one Bing Maps control on each form. If you need to show more than one map, consider using a web resource or an IFRAME.


Quick View Forms

Quick View forms are embedded in child forms to show data of parent records. This type of form includes one tab that has one column, which can have more than one section. Sections can have fields, subgrids, or spacers. Information that is shown in a Quick View form is read-only.

You can use a Quick View form to view parent account details or primary contact details on the Main form. If you select Insert > Quick View Form, you can select for which lookup field you want to see the Quick View form and then select the Quick View form (see Figure 22.20).

Image

FIGURE 22.20 Embedding a Quick View form.

There is a special Quick View form in the system that you can customize, the Hierarchy Tile form. This form is available for the following entities:

Image Account

Image Position

Image Product

Image User

You can use the Hierarchy Tile form to customize the tiles shown in the hierarchy view of these entities.

Quick Create Forms

A Quick Create form is a shortened version of a form that includes important fields for creating a record. A Quick Create form does not have any subgrids or other components. It has one tab with three columns, and each column has a single-column section.

When you click + on the top navigation bar, you see a list of entities. If you select the Account entity, you are then presented with a Quick Create form, as shown in Figure 22.21.

Image

FIGURE 22.21 Quick Create form for an account.


Tip

You can have multiple Quick Create forms; however, only one will be displayed to the user. If you create a new Quick Create form for an entity that is not listed here, make sure the entity has the Allow Quick Create option set in the entity properties.


Card Form

The Card form is a new type of form in Dynamics CRM 2016. This type of form is used in the interactive service hub.

Image For more information about the interactive service hub, refer to CHAPTER 11, “The Interactive Service Hub”.

Main-interactive Experience

The Main-interactive Experience form is a new type of form in Dynamics CRM 2016. This type of form is used in the interactive service hub. The following sections describe the customizations you can make to these forms.

Editing the Form Navigation

You can easily modify the form navigation links without having to touch the Site Map directly. By clicking the Navigation button, you can remove or add links to the form navigation bar.

Changing Form Properties

Here you have access to the general form properties. These properties are not visible to the user; they include such events as form assistance integration and nonevent dependencies fields.

Previewing Form Customizations

Dynamics CRM 2016 has enhanced the Preview form features, which allow a user to preview form changes in the mobile client without having to go to a mobile device and then preview the changes in the desktop computer.

After you complete your customizations to a form, you can easily preview them by clicking the Preview button and choosing either Desktop Client or Mobile Client and then selecting a form mode option.

For the desktop client you can select Create Form, Update Form, or Read-Only Form.

For the mobile client you can select Tablet or Phone, as shown in Figure 22.22.

Image

FIGURE 22.22 Preview menu items for the mobile client.

Selecting one of the mobile options takes you to the mobile preview screen, which first downloads the metadata changes. Once the metadata is loaded, which might take a few minutes, you get an emulator screen, as shown in Figure 22.23.

Image

FIGURE 22.23 Preview for the mobile client.

You can easily switch from Phone to Table without leaving the emulator screen by using the icons next to Platform in the top-right corner of the emulator. Notice that this is not a full phone or tablet emulator where you can run other apps; this emulator has limited interaction, and its only purpose is to help you preview the forms in mobile devices.

Image Refer to CHAPTER 18, “Mobility,” for more information about mobile client features and visual controls.

When you are done with the customizations, you can click Save and Close to save your work.


Note

Customizations to the forms will not be visible and usable by users until they are published. See the “Publishing Customizations” section on the next page for how to do this.


View Customizations

A view is a read-only representation of an entity’s records. It shows just a few of the entity’s fields. You can see views in the Advanced Find results and in the Look Up Records results.

Several different types of views are created by default for each entity, and you can easily create new views. For each view, you can customize the fields to be displayed by adding, removing, or changing the display position of the columns. You can also set the desired width, in pixels, for each column. By default, the columns have a fixed width of 100 pixels, and the options available for column width are fixed at 25px, 50px, 75px, 100px, 125px, 150px, 200px, and 300px.

Publishing Customizations

When you have completed your desired changes to an entity, you must publish the customizations so that users can see and use them. To publish, select the entity you want to publish and then click either Publish on the entity/form you’re working with or the Publish All Customizations button.


Note

If you delete an entity or a field, you don’t need to publish the customizations. The deleted entity or field will be unavailable to users as soon as you delete it.

After you make a customization to either a form or a view, you must publish it in order for users to see the change.


Preparing Client Customizations

Update 0.1 of Dynamics CRM 2016 introduced a new option for deployments which is used to improve the performance experience for mobile clients and with the interactive service hub. Users must wait for all the metadata updates after you publish the customizations, but clicking this option makes that wait time shorter.

Menu and Command Bar Customizations

Ribbons in CRM 2011 were replaced by a command bar in CRM 2013, and CRM 2016 still uses the command bar.


Note

The ribbon is still present in nonrefreshed entity forms such as Connection and in the list view in Microsoft Outlook.


The command bar still uses the RibbonDiffXML structure, but it is rendered differently in the user interface.

You can customize the navigation bar and controls in three ways:

Image Site Map

Image ISV Config

Image Command bars

All three of these methods require a little knowledge about managing XML files. When working with XML files, remember the following rules:

Image XML files are case sensitive, so be sure to respect the case of each node name to avoid problems. For example, the node name <root> is not the same as <ROOT>.

Image Each node needs to be closed. For example, if you open a node with <root>, you need to later close it with </root>. If the node doesn’t contain child nodes, you can open and close it in the same line (for example, <root />).


Note

For more information about working with XML files and their specifications, visit www.w3.org.



Tip

Although XML files can be edited with any text editor, such as Notepad, I recommend using a richer text editor, such as Visual Studio. From there, you can see the nodes colored, and you can also expand and collapse the nodes. In addition, you can take advantage of IntelliSense by assigning the schema files included in the CRM SDK, in the SDKSchemas folder, and using the CustomizationsSolution.xsd file.


Site Map

The Site Map is the file that describes the items that will be shown in each area. For example, when you are in the Sales area, you can select any of these options: Dashboard, Activities, Calendar, Imports, and so on. These options are quick links to the entity’s administration that you can customize when you want to have another frequently used entity.

The Site Map is an XML file that needs to be exported first to be edited, and then it needs to be reimported to be updated. It is recommended that you create a new custom solution with only the Site Map extension to update the Site Map quickly. Go to Settings > Solutions > New, enter the display name for your solution, press Tab to quickly populate the Name field, select the publisher and enter the Version number, and click Save. Then select the view Client Extensions, as shown in Figure 22.24.

Image

FIGURE 22.24 Locating the Site Map customization by using the Client Extensions view.


Note

To make changes to the Site Map without having to touch the XML directly, I recommend the CRM Sitemap Editor tool that you can download for free from www.crmsolutionmanager.com/Download.aspx.


Image For more information about exporting the Site Map, SEE the “Exporting and Importing Entity Customizations” section, later in this chapter.

The following code illustrates the Site Map node structure:

<Site Map>
        <Site Map>
            <Area>
                <Group>
                     <SubArea>

Site Map Node

Site Map is the main and root entry-level node. Inside this node is another node with the same name, Site Map, which contains all the Area nodes as children.

Area Node

Each Area node provides the main navigation buttons displayed on the main interface. By default, the Site Map is configured with five main areas:

Image Sales

Image Service

Image Marketing

Image Settings

Image Help Center

The following code illustrates the Area node with its default attributes for the Sales area:

<Area Id="SFA" ResourceId="Area_Sales" DescriptionResourceId="Sales_Description"
Icon="/_imgs/sales_24x24.gif" ShowGroups="true" IntroducedVersion="7.0.0.0">

These are the attributes of the Sales area node:

Image Id—This is the unique identifier for each area.

Image ResourceId—This is the resource identifier.

Image ShowGroups—This attribute is necessary only if the area has more than one group child node.

Image Icon—This is the URL for the icon to be displayed near the area title.

Image DescriptionResourceId—This is for internal use only.

Image IntroducedVersion—This gives the version where this area was introduced; 7.0.0.0 means CRM 2015, and 8.0.0.0 means CRM 2016.

Group Node

The Group node contains a group of SubArea nodes. Each group is displayed in the navigation bar. Types of groups include My Work and Customers, which are included by default in the Sales area.

SubArea Node

A SubArea node is used to provide a link to a page or website (configured by its URL) inside a Group section.

Suppose, for example, that you want to add a new area to the Site Map called Webfortis to be used as a collection of links related to the organization and external application. You could edit the Site Map by adding the code in Listing 22.1 to the Site Map file right after the last </Area> node and before the </SiteMap>.

LISTING 22.1 Adding a New Area to a Site Map

<Area Id="WebfortisArea" Title="Webfortis" ShowGroups="true"
Icon="/_imgs/resourcecenter_24x24.gif" >
       <Group Id="Group1" Title="External">
              <SubArea Id="nav_SubArea1" Title="Website"
Icon="/_imgs/ico_18_129.gif" Url="http://www.webfortis.com" />
              <SubArea Id="nav_SubArea2"  Title="Microsoft"
Icon="/_imgs/ico_16_sales.gif" Url="http://www.microsoft.com"
AvailableOffline="false" />
       </Group>
       <Group Id="Group2" Title="Internal">
              <SubArea Id="nav_SubArea11" Title="Intranet"
Icon="/_imgs/ico_18_129.gif" Url="http://www.webfortis.com/Internal"
AvailableOffline="false" />
              <SubArea Id="nav_SubArea12" Title="Cost Control"
Icon="/_imgs/ico_16_sales.gif" Url="http://www.webfortis.com/CC"
AvailableOffline="false" />
       </Group>
</Area>

Next, you save the changes and import the solution that contains the Site Map. To import the Site Map customizations, go to Settings > Solutions > Import. Then upload the customizations you edited and click the Import Selected Customizations button.

Image For detailed instructions on how to import Site Map customizations, SEE the “Exporting and Importing Entity Customizations” section, later in this chapter.


Note

Important considerations when adding a new Area, Group, or SubArea are to be sure to use unique names for the Id attributes and to not use the ResourceId and DescriptionResourceId attributes in your custom elements (because they are for internal use only). Instead, use the Titles and Title elements to display the text for the different languages.


ISV Config

ISV Config is an XML structure that is part of the customizations.xml file included in every solution. The only functionality of ISV Config is to provide the appearance and behavior of the Service Calendar.

To be able to work with the ISV Config XML, you need to explicitly specify it when importing the solution by selecting the ISV Config option, as shown in Figure 22.25.

Image

FIGURE 22.25 Export System Settings dialog, choosing ISV Config.

Notice that because ISV Config is considered a system setting, any customization made here is not removed when you remove the solution. Listing 22.2 illustrates the main node structure in the ISV Config XML.

LISTING 22.2 Main Node Structure for the ISV Config XML

<IsvConfig>
    <configuration version="3.0.0000.0">
      <Root />
      <ServiceManagement>
        <AppointmentBook>
          <SmoothScrollLimit>2000</SmoothScrollLimit>
          <TimeBlocks>
            <TimeBlock EntityType="4214" StatusCode="1"
CssClass="ganttBlockServiceActivityStatus1" />
            <TimeBlock EntityType="4214" StatusCode="2"
CssClass="ganttBlockServiceActivityStatus2" />
            <TimeBlock EntityType="4214" StatusCode="3"
CssClass="ganttBlockServiceActivityStatus3" />
            <TimeBlock EntityType="4214" StatusCode="4"
CssClass="ganttBlockServiceActivityStatus4" />
            <TimeBlock EntityType="4214" StatusCode="6"
CssClass="ganttBlockServiceActivityStatus6" />
            <TimeBlock EntityType="4214" StatusCode="7"
CssClass="ganttBlockServiceActivityStatus7" />
            <TimeBlock EntityType="4214" StatusCode="8"
CssClass="ganttBlockServiceActivityStatus8" />
            <TimeBlock EntityType="4214" StatusCode="9"
CssClass="ganttBlockServiceActivityStatus9" />
            <TimeBlock EntityType="4214" StatusCode="10"
CssClass="ganttBlockServiceActivityStatus10" />
            <TimeBlock EntityType="4201" StatusCode="1"
CssClass="ganttBlockAppointmentStatus1" />
            <TimeBlock EntityType="4201" StatusCode="2"
CssClass="ganttBlockAppointmentStatus2" />
            <TimeBlock EntityType="4201" StatusCode="3"
CssClass="ganttBlockAppointmentStatus3" />
            <TimeBlock EntityType="4201" StatusCode="4"
CssClass="ganttBlockAppointmentStatus4" />
            <TimeBlock EntityType="4201" StatusCode="5"
CssClass="ganttBlockAppointmentStatus5" />
            <TimeBlock EntityType="4201" StatusCode="6"
CssClass="ganttBlockAppointmentStatus6" />
          </TimeBlocks>
        </AppointmentBook>
      </ServiceManagement>
    </configuration>
  </IsvConfig>

ServiceManagement Node

The ServiceManagement node customizes the service calendar. The ServiceManagement node contains only a child node with the name AppointmentBook. The AppointmentBook node can have one of these nodes:

Image SmoothScrollLimit—This option sets the maximum number of blocks to be displayed by a service activity before autoscrolling the appointment when it is selected or displayed.

Image ValidationChunkSize—This option is used to configure the number of activities to be validated simultaneously by the server. The validation occurs in cases where more than one activity requires the same resources or materials.

Image TimeBlocks—This is the reserved time during which a service can start.

Image Refer to CHAPTER 10, “Working with Service,” for more information about the ServiceManagement node.

With each TimeBlock element, you can apply a different style to each status code of a service activity. Consider this example:

<ServiceManagement>
   <AppointmentBook>
     <SmoothScrollLimit>2000</SmoothScrollLimit>
     <TimeBlocks>
       <!-- All CSS Class mapping for Service activities -->
       <TimeBlock EntityType="4214" StatusCode="1"
[ccc]CssClass="ganttBlockServiceActivityStatus1" />
     </TimeBlocks>
   </AppointmentBook>
</ServiceManagement>

The EntityType attribute can be one of the following values:

Image 4214—Service activity

Image 4201—Appointment

The Command Bar

As mentioned earlier in this chapter, CRM 2016 uses a command bar rather than a ribbon. You can customize the Dynamics CRM command bar by adding custom buttons. The command bar provides a new way of displaying buttons and provides better performance. Command bars are located three main places:

Image Grid (Mscrm.HomepageGrid)HomepageGrid is located in the home page of any entity where the main grid is located.

Image Subgrid (Mscrm.SubGrid)—The command bar for subgrids located on forms.

Image Form (Mscrm.Form)—The entity record shows the command bar located on the top of the form.

Adding a simple button to a command bar involves editing the customization file to include nodes in the RibbonDiffXml node, adding web resources for the images to be displayed in the button, and adding a web resource for the JavaScript method to be used when clicking the button.


Note

Much like editing the Site Map, as was discussed earlier in this chapter, I recommend using a visual ribbon editor for easier modifications. The Ribbon Workbench is one such tool, and it’s available at www.develop1.net/public/Download%20Ribbon%20Workbench%202013.aspx.


Command Bar Buttons

The command bar can show a maximum of nine buttons at any time, with the rest moving to the overflow (ellipsis) section. This is a welcome enhancement to previous versions, which showed a maximum of five or seven. The command bar does not display a button if it is disabled, and because the command buttons are smart and can change while the user is using the application, there are some rules that need to be configured for this case so that you can make a button visible or enabled, depending on the following conditions:

Image Based on form state—The Create, Existing, Read Only, Disabled, and Bulk Edit buttons are enabled or disabled based on form state.

Image Configure custom rules—You can write custom rules by using JavaScript functions with the following parameters:

Image CrmClientTypeRule—Detects whether running in the Outlook client or web client.

Image CommandClientTypeRule—Detects whether running in the Outlook client, the CRM for tablets client, or the web client.

Image CrmOfflineAccessStateRule—Detects whether Outlook is running in offline or online mode.

Image CrmOutlookClientTypeRule—Types CrmForOutlook or CrmForOutlookOfflineAccess.

Image OrRule—Contains a collection of rules so that this rule evaluates as true if any of the rules in the collection evaluates as true.

Image OutlookItemTrackingRule—Detects whether the item is enabled for items tracked in Microsoft Dynamics CRM to enable a ribbon element.

Image OutlookVersionRule—Detects the version of the Microsoft Office Outlook client.

Image PageRule—Evaluates the address of the current page.

Image RecordPrivilegeRule—Detects a user’s privileges for a specific record in order to enable a ribbon element.

Image SkuRule—Detects the Microsoft Dynamics CRM edition.

Image ValueRule—Detects the value of a specific field.

Image ReferencingAttributeRequiredRule—Detects whether the referencing attribute for an entity is required.

Image RelationshipTypeRule—Detects whether a specific type of formal entity relationship exists between two entities.

Image EntityPrivilegeRule—Detects the current user’s privileges for a specific entity.

Image EntityPropertyRule—Detects specific Boolean entity properties.

Image FormEntityContextRule—Detects whether a form ribbon is displayed in the context of a specific entity.

Image HideForTabletExperienceRule—Specifies when the web application is viewed in a mobile browser on a tablet device.

Image MiscellaneousPrivilegeRule—Detects whether the user possesses a specific Microsoft Dynamics CRM privilege.

Image OrganizationSettingRule—Detects two specific organization settings within a DisplayRule: IsSharepointEnabled and IsSOPIntegrationEnabled.

Image OutlookRenderTypeRule—Detects whether a form or list item is rendered as a web page or natively in Outlook in order to determine whether a ribbon element should be displayed.

Image SelectionCountRule—Detects how many items in a grid are selected.

The display rule named CommandClientTypeRule shows buttons on the command bar if they do not have any CommandClientTypeRule associated with them, and if associated, they should have Type="Refresh". The Type property can have the following values:

Image Modern—The button is visible in tablets.

Image Refresh—The button is presented using an updated interface (that is, the command bar).

Image Legacy—The button is visible on nonrefreshed entities such as Connection and in the list view of Microsoft Outlook.

The SDK comes with samples that help you easily add custom buttons to an existing group for all entities or add custom buttons to an existing group for specific entities. In addition, you can add custom groups to an existing tab for a specific entity, add a custom tab to a specific entity, add custom groups to the Developer tab for all entities in a form, and hide ribbon elements. The SDK includes all the XML files for the system entity ribbons, in the SDKResourcesExportedRibbonXml folder.


Note

There is also a good source code sample called ExportRibbonXml in the SDK, in the SDKSampleCodeCSClientRibbon folder. It exports all the entities’ XML ribbon data so that you can use it to easily locate each ribbon tab, group, or button.


RibbonDiffXml

The RibbonDiffXml node defines the tabs, groups, and buttons, and it contains the following child nodes:

<RibbonDiffXml>
        <CustomActions />
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions />
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules />
          <EnableRules />
        </RuleDefinitions>
        <LocLabels />
</RibbonDiffXml>

The CustomActions node defines the tabs, groups, and buttons and contains the following child nodes:

<CustomActions>
  <CustomAction >
    <CommandUIDefinition>
        <Controls>
          <Button />
        </Controls>
    </CommandUIDefinition>
  </CustomAction>
</CustomActions>

The Button node contains the following attributes:

Image Id—The unique identifier for the button.

Image Command—The ID of the command that will be defined in the CommandDefinitions node of the RibbonDiffXml root node. Each command definition is defined as follows:

    <CommandDefinitions>
      <CommandDefinition Id="Solution.all.HomepageGrid.MyGroup.Help.Command">
        <EnableRules />
        <DisplayRules />
        <Actions>
          <JavaScriptFunction FunctionName="ShowHelp"
Library="$webresource:webforti_Script.js" />
        </Actions>
      </CommandDefinition>
    </CommandDefinitions>

Inside the command definitions, you can include the rules for enabling or disabling the buttons (inside the EnableRules node), and you can show or hide the buttons (in the DisplayRules node) and the actions to be performed when the button is clicked:

Image Sequence—The integer number of the sequence to define the position of the button related to the other buttons in the same group.

Image LabelText—The ID of the localized label that is defined inside the LocLabels node. Here is an example:

<RibbonDiffXml>
    ...................
    <LocLabels>
      <LocLabel Id="Solution.all.HomepageGrid.MyGroup.Help.ToolTip">
        <Titles>
          <Title languagecode="1033" description="Help" />
        </Titles>
      </LocLabel>
   </LocLabels>
</RibbonDiffXml>

Inside the Titles node, you can enter as many Titles node languages as you want. In this example, languagecode="1033" refers to the English language.


Note

For a complete list of language codes, see http://msdn.microsoft.com/en-us/library/0h88fahh.aspx.


Image ToolTipTitle—The ID of the localized label that is defined inside the LocLabels node, similar to the LabelText node.

Image ToolTipDescription—The ID of the localized label that is defined inside the LocLabels node, similar to the LabelText node.

Image TemplateAlias—The alias of the template to be used; this affects the way the button will be displayed; o1 displays the button big, and o2 displays the button small.

Image Image16by16—The ID of the web resource used for the 16-by-16-pixel image. This is the image used for small buttons. If you use a web resource, you need to enter a value as follows: $webresource:name of the web resource.png.

Image Image32by32—The ID of the web resource used for the 32-by-32-pixel image. This is the image used for big buttons. If you use a web resource, you need to enter a value as follows: $webresource:name of the web resource.png.


Note

You might wonder whether you need to use either the Image16by16 or Image32by32 attributes; however, it is recommended that you set both because some templates use one or the other, depending on the window’s size.


JavaScript Events

JavaScript events are related to forms and the controls inside the forms only. Each form has OnLoad and OnSave events, which can accept JavaScript. Each field also has the OnChange event, which can also accept JavaScript. You can also add events for the Tab control to track the TabStateChange event and to IFRAMEs to track the OnReadyStateComplete event (see Figure 22.26). Dynamics CRM 2011 supported the crmForm.all object collection, but CRM 2016 does not; instead, the Xrm.Page object collection is used for CRM 2016 JavaScript customizations.

Image

FIGURE 22.26 Form events that you can customize with JavaScript.

The list of JavaScript events is as follows:

Image OnLoad event—Occurs every time the window of an entity is open, either when you edit an existing record or when you create a new one.

Image OnSave event—Occurs every time the save icon or the Save and Close button is pressed.

Image OnChange event—Fires every time the value of the field is changed and after it loses the focus.

Image TabStateChange event—Occurs every time the user switches from one tab to the other.

Image OnReadyStateComplete event—Fires when the content of the IFRAME has been loaded.

To start adding script to this event, you need to create a web resource of type JavaScript that you can use as a library where you can have a common repository for the event scripts you will handle. This allows you to reuse the JavaScript function on different forms and entities.


Note

Microsoft released a tool named the Custom Code Validation Tool. This tool lets you know which scripts don’t work in CRM 2015/2016 (CRM 4.0 or 2013 code, some common DOM manipulations, and so on). You can download this tool from www.microsoft.com/en-us/download/details.aspx?id=45535. Notice while the tool says it is for CRM 2015, it works for CRM 2016.


Event-Handling Tips and Tricks

CRM releases since CRM 2011 Rollup 12 provide support for multiple browsers. You can run Dynamics CRM in any browser, including Internet Explorer, Firefox, Chrome, and Safari.

It used to be possible to easily access the DOM in JavaScript. This is not recommended now, though, because these scripts might work on one browser and not on another. As a result, you should not try to access DOM objects in your scripts. Instead, you can attach functions to the onChange event or field through form customization, or you can simply do the same thing by using the addOnChange method. Suppose that you have a custom entity called House to which you have added the following custom fields: Width, Height, and Area. In this case, you want to have the field area automatically change based on the width and height of the fields displayed. You could add the Listing 22.3 code in the OnLoad event to attach an onChange event to the field control.

LISTING 22.3 Attaching the onChange Event to a Field Control

function setupEvents()
{
 Xrm.Page.getAttribute("webforti_height").addOnChange(doCalc);
 Xrm.Page.getAttribute("webforti_width").addOnChange(doCalc);
}
function doCalc()
{
var area= Xrm.Page.getAttribute("webforti_height").getValue() * Xrm.Page.
getAttribute("webforti_width").getValue();
 Xrm.Page.getAttribute("webforti_area").setValue(area);
}

To see this example at work, follow these steps:

1. Go to Settings > Customizations > Solutions.

2. Create a new solution and go to Entities.

3. Click New to create a new entity.

4. Enter House in the Display Name field and Houses in the Plural Name field.

5. Click the Save button but do not close the window.

6. Click Fields from the Common section in left-side navigation.

7. Click the New button to add the custom field.

8. Enter Height in Display Name and select Whole Number in the Type field.

9. Click Save and Close to save the field.

10. Repeat steps 7 through 9, but this time enter Width as the Display Name.

11. Repeat steps 7 through 9, but this time enter Area as the Display Name.

12. Click Fields from the Common section in left-side navigation.

13. Double-click the Information Main type form record to edit it.

14. Drag and drop the new attributes you created: Height, Width, and Area.


Tip

Click the General section and double-click the fields to easily add them to the section.


15. Click Form Properties on the Home tab of the ribbon. The Form Properties dialog appears (see Figure 22.27).

Image

FIGURE 22.27 Form Properties dialog.

16. Click Add in the Form Libraries section. The Look Up Record dialog appears (see Figure 22.28).

Image

FIGURE 22.28 Web resources lookup.

17. Click New to create a new JavaScript file.

18. Enter mainlib.js in the Name and Display Name fields and select the Script (JScript) type, as shown in Figure 22.29.

Image

FIGURE 22.29 Creating a new JavaScript web resource.

19. Click Text Editor and enter the code in Listing 22.4, as shown in Figure 22.30.

LISTING 22.4 Code for the JavaScript Web Resource Event

function setupEvents()
{
 Xrm.Page.getAttribute("webforti_height").addOnChange(doCalc);
 Xrm.Page.getAttribute("webforti_width").addOnChange(doCalc);
}
function doCalc()
{
var area= Xrm.Page.getAttribute("webforti_height").getValue() * Xrm.Page.
getAttribute("webforti_width").getValue();
 Xrm.Page.getAttribute("webforti_area").setValue(area);
}

Image

FIGURE 22.30 Adding code to the JavaScript web resource event.

20. Click the OK button to close the text editor.

21. Click Save, click Publish, and then close the Web Resource dialog.

22. Select the new web resource you created and click Add.

23. In the form library you added, go to the event handlers and set Control to Form and Event to OnLoad. Click Add.

24. Type setupEvents in the Function field (see Figure 22.31).

Image

FIGURE 22.31 Handler Properties dialog box.

25. Click OK to close the Handler Properties dialog. Click OK to close the Form Properties dialog.

26. To test the code, select Preview > Create Form. Alternatively, you can publish all the customization and view the entity directly.

27. Enter a value on the Height field (for example, 10) and enter a value to the Width field (for example, 10). The Area field is set automatically with the calculated result, 100.


Note

Notice that the field names might vary depending on the solution prefix, which is set on the Publisher record that is associated to the solution (and is limited to eight characters). This example uses webforti_, but you might use new_ or some other prefix.


When working with JavaScript code, it is important to publish the JavaScript web resource every time you make a change to it so that you can preview your changes.

Tips and Tricks When Working with Events

When you work with JavaScript code, you encounter some disadvantages of using the regular web interface:

Image The interface lacks IntelliSense.

Image The JavaScript code is not colored for better understanding and manipulation.

Image It is tedious to debug and correct errors in some situations when you can’t use the preview feature to simulate your changes. Instead, you need to manipulate the code, save the changes, publish the updates, and then see whether it works as expected.

To avoid all these disadvantages, you can use a richer JavaScript editor, such as Visual Studio. When working with JavaScript in Visual Studio, having the script located in a separate web resource enables you to easily copy and paste the script from CRM to Visual Studio. That way you can get access to IntelliSense and colored code. A good technique for debugging scripts is to enable the Internet Explorer debugger. You can do this by going to Tools > Internet Options and selecting the Advanced tab. Be sure that you have unchecked the Disable Script Debugging (Internet Explorer) and Disable Script Debugging (Other) options.

When you have script debugging enabled, you can put the sentence debugger on your code to start the debugger. Here’s an example:

function setupEvents()
{
debugger;
 Xrm.Page.getAttribute("webforti_height").addOnChange(doCalc);
 Xrm.Page.getAttribute("webforti_width").addOnChange(doCalc);
}

When you run this code on the OnLoad event, the dialog shown in Figure 22.32 opens, enabling you to select the debugger you want—in case you have Visual Studio installed on your machine.

Image

FIGURE 22.32 Launching a debugger from JavaScript code.

This is a good technique for debugging JavaScript code because normal users will have the script debugger disabled by default and won’t get rich error messages that tell them exactly what broke.


Tip

A good utility for working with JavaScript customizations is the Internet Explorer Developer Tools, available inside Internet Explorer. Just press the F12 key while in Internet Explorer.


Calculated Fields

This section shows the same example from the preceding sections but this time using calculated fields. The new calculated field feature allows you to get the solution shown before but without doing any JavaScript development.

Go to Fields and create a new calculated field with the name Calculated Area, with the Data Type field set to Whole Number, as shown in Figure 22.33.

Image

FIGURE 22.33 New Calculated Field.

Click Edit button, then under Action, Click Add Action and enter “webforti_height * webforti_width” and click on the checkmark icon (see Figure 22.34).

Click Save and Close.

Image

FIGURE 22.34 Calculated formula.

Add the new field to the form and try it. You see the calculated Area field updated as soon as you save the record. The field is read-only, preventing other users from manually entering values there.

Business Rules

Business rules give non-developer users the ability to add logic to fields without adding JavaScript code. Before business rules, simple logic required some knowledge of JavaScript. Even if you have good knowledge of JavaScript already, it’s worth getting a good understanding of the business rules because they can save a lot of time. Business rules can be run in the server scope, doing work that custom plug-ins used to be required to do.

You can access to the business rules in different ways. One way is to open a solution and expand Entities and then a specific entity, as shown in Figure 22.35.

Image

FIGURE 22.35 Business rules from a solution.

Another way to access the business rules is to open a form and click the Business Rules button on the Home tab of the ribbon.

If you click the New Business Rule button in the bottom-right corner of a form, you can create a business rule for that form. Later, you can change the scope, which can be any of the following.

Image Entity (server and client)

Image All forms (client only)

Image Specific form (client only)

A business rule must have a name, and it must be activated in order to be used by users. When you create a new business rule, it starts in a draft state, where you can add conditions and actions. Activating the business rule makes the business rule read-only so no changes can be made while the rule is active. Remember to publish all customizations after activating a business rule.

The conditions used by business rules are similar to the conditions you find in the Advanced Find tool with the exception that you can compare fields with other field values.

You can use business rules to do the following actions:

Image Show error messages.

Image Set a field value.

Image Set a rule as required.

Image Set visibility. You can show or hide a field based on a condition.

Image Set default values. You can set a default value based on a condition.

Image Lock or unlock a field.

Showing Error Messages

You can use a business rule to show an error message based on a condition or validation. Figure 22.36 shows how to design a business rule using this action.

Image

FIGURE 22.36 Design of a business rule to show an error message.

Once the business rule is activated, the user sees the error shown in Figure 22.37.

Image

FIGURE 22.37 Business rule showing an error message in action.

The error and logic validation are shown before and/or after the form is saved, preventing invalid data from being inserted or updated to the CRM system.


Note

Notice that if you create this error message business rule and have the scope set to Entity, any application that tries to create or update an entity with a business rule triggers the error message.


Setting a Field Value

You can use a business rule to set a value for a field, based on a condition. You can set a fixed value or a constant, you can set the value of another field, and depending of the type of the field, you can use formulas or can clear the value to make the field blank.

Using the same example used earlier for JavaScript and the calculated field, you can now calculate the area of a house by using a business rule, as shown in Figure 22.38.

Image

FIGURE 22.38 Set Field Value action.

Making a Field Required

You can use a business rule to makes a field required or not required, based on a condition. This action can be useful if you want a field to be required in one form and not in other forms. Or you can make a field required only if another field has a value, based on a condition (see Figure 22.39).

Image

FIGURE 22.39 Set Business Required action.

Setting Visibility

You can use a business rule to show or hide fields based on conditions. The Set Visibility action has no effect on the server side when you set the Entity scope as it is applied only when a form is loaded in the web client or the mobile client (see Figure 22.40).

Image

FIGURE 22.40 Set Visibility action.

Setting Default Values

You can use a business rule to set a default value for a field, based on a condition. You can set a fixed value or a constant, you can set the value of another field, and depending of the type of the field, you can use formulas or can clear the value to make the field blank.

You may wonder why there are two similar actions—Set Field Value and Set Default Value—and when to use each one. The answer is simple: You use Set Default Value to initialize fields that then can be replaced by values entered by the user; using Set Field Value may overwrite users’ entries when evaluating the business logic every time a record is loaded on a form. This was a common issue users faced in older versions of Dynamics CRM, such as CRM 2013, which don’t include the Set Default Value action.

Locking or Unlocking a Field

You can use a business rule to set a field as read-only, based on a condition. In this case, you must select a field and a status, which can be either Lock or Unlock.

Exporting and Importing Entity Customizations

You can export all customizations made on any entity out of the CRM system to be used on other CRM implementations or for backup purposes. You can achieve this by using solutions.

Image Refer to the section “Solution Concepts,” later in this chapter, for more details about how to work with solutions, as well as how to export and import customizations as part of solutions.


Note

An important consideration when importing customizations is that they can only add or append new attributes to existing entities and don’t delete any missing attribute or data. So there is no risk of losing the data you or any other user added if you had previously added a new attribute and then you import an older version that does not include that attribute. However, any new fields you added to the form or the views are removed in this case.

Another important consideration is that if you delete a managed solution, the new entities and data that belong to that solution are deleted. However, the data and entity are not deleted if you remove an unmanaged solution. To restore any custom entity you created with the data inside a custom solution, you must also manually delete the entity in the default solution.


When importing customizations for the Site Map, you might accidentally delete the Settings area or import an error file that breaks the web application. If that happens, you can use the following link to directly access the Import Customization interface to restore a backup and take the application to a good state, as shown in Figure 22.41: http://servername:port/organizationname/tools/systemcustomization/systemcustomization.aspx.

Image

FIGURE 22.41 Customizations interface for recovering a broken application.

For example, the link for an On-Premises deployment might be as follows: http://crm2016/webfortis/tools/systemcustomization/systemcustomization.aspx. And the link for an Online deployment might be the following: https://webfortis2016.crm.dynamics.com/tools/systemcustomization/systemCustomization.aspx.

Solution Concepts

When making changes to a system, organizations typically need to modify entities’ views or forms or modify and add new attributes to the entities (or even add new entities). These changes can be as small as adding or removing a desired field to completely changing how the system works with custom workflows and code. When making a change to the system, these changes are captured in a solution, which is a package that contains the changes. A system may have no custom solutions, or it may have many solutions. In addition, solutions can be used to interact with components from one another, and they may even be dependent on each other.

Many of the solutions that currently exist in CRM and xRM environments involve other pieces of software, such as plug-ins, reports, custom static/dynamic pages, images, scripts, Silverlight applications, templates, and web services, just to name a few.

Solutions help you in the deployment, support, upgrade, sale, and distribution of all the customizations you can think of. Each solution is compiled into a single zip file that contains the following components:

Image Entities

Image Option sets

Image Client extensions

Image Web resources

Image Processes

Image Plug-in assemblies

Image SDK message processing steps

Image Service endpoints

Image Dashboards

Image Reports

Image Connection roles

Image Article templates

Image Contract templates

Image Email templates

Image Mail merge templates

Image Security roles

Image Field security profiles

Image Routing rule sets

Image Record creation and update rules

Image SLAs

By default, each CRM organization has a base solution, known as the default solution, which cannot be deleted. To work with the default solution, go to Settings > Customizations and then click Customize the System, as shown in Figure 22.42.

Image

FIGURE 22.42 Default solution.


Note

Even though you can customize the default solution, it is strongly recommended that you not do this but instead create a custom solution and work with any customizations there. The reason for this is that a custom solution can easily be rolled back to its original state when needed, such as when it’s imported as managed to another organization. Customizations in unmanaged solutions cannot be rolled back after the solution is removed.


Working with Custom Solutions

To work with custom solutions, go to Settings > Customization > Solutions, as shown in Figure 22.43.

Image

FIGURE 22.43 Solutions.

To create a new solution, following these steps:

1. Click New. You see a screen similar to the one shown in Figure 22.44.

Image

FIGURE 22.44 A new solution.

2. To create a new publisher, select Look Up More Records, select New, and complete the information on the form. (If this is the first time you have created a solution, you need to create a publisher for it or use the default publisher for the organization. For this example, I’ve created a new publisher, CRMPMG, but I still have the default one as an option.)


Note

Publishers are helpful in that they provide a mechanism for updating and managing solutions. Because you can control the prefix and option value, you can manage when and who creates a solution via the publisher, which is especially important when you’re working with managed solutions.



Note

Even though the description is not required to create a publisher in CRM, it is required if you want to publish the solution to the Dynamics Marketplace, as you will see later in this chapter, so it is recommended that you enter a company description and fill in all the fields in the Contact Details tab (for phone number, email, website, address, state, city, and country).



Tip

To see the list of publishers, go to Settings > Customizations and then click Publishers.


3. In the Look Up Record dialog, because the new publisher you created in the previous step is selected by default, click OK.

4. Enter a display name, a name, and a version for your solution. Note that you can press the Tab key after entering the display name to autopopulate the Name field, but you can change this if desired.


Tip

The version number is not autopopulated, so you should expect to enter a value here.


5. Click Save to enable all the items in the left-side navigation area.

Each solution can contain a configuration page, which is a web resource that can be used to provide general settings as well as license keys configured for independent software vendor (ISV) providers. Those license keys can be managed and verified using custom plug-ins.


Note

As with the Publisher description, the Solution description is not required for creating a solution in CRM. However, it is required if you want to publish the solution to the Dynamics Marketplace.


To create a configuration page, create an HTML file and add it as a web resource to the solution. To do this, click Web Resources > New, enter a name and a display name for the configuration page, select Webpage (HTML) as the type in the Content area, and then select the language and upload the HTML file you created (see Figure 22.45).

Image

FIGURE 22.45 Creating a configuration page.

Then click Save and Close, and you can click the Information link to assign the configuration page to your solution.


Caution

You must publish the new HTML web resource before assigning the configuration page, or you will get an error when you try to work with the resource.


Click Save, and you see that the configuration page can now be accessed from a new link that appears in left-side navigation area, with the name Configuration.

Solution components share some functions, and some others depend on the component type. The functions shared by all components are discussed in the following subsections.

Adding Required Components

The Add Required Components function is available on all component types and requires you to select a component from the list before you can use it. It is useful, for example, when you create a dashboard that contains a chart on the Account entity or any other system or managed entity. Clicking the Add Required Components button adds the Account entity to the entity’s components so that you can be sure it will be part of the solution.

The same happens with reports and processes. If you have a workflow that needs to create a record of any of the system entities, the Add Required Components feature adds that entity to the entity’s component.


Note

Note that the Add Required Components function does not work for custom code, where you can add web resources with JavaScript or by calling the CRM web services from an event of a form or field.


Showing Dependencies

New in Dynamics CRM 2016 is the addition of the Show Dependencies button, which quickly shows you the decencies for the selected component so you can evaluate them before clicking Add Required Components. This function is useful when you want to delete a custom component because the CRM system won’t let you do it if you have dependencies on that component. Figure 22.46 shows the dependencies for the custom House entity.

Image

FIGURE 22.46 Showing dependencies for the custom House entity.

This option is also available when you are in the form editor. If you click the Show Dependencies button there, you see any web resource you may have referenced that the forms depends on.

Managed Properties

There are two types of solutions: managed and unmanaged. Unmanaged solutions are used for development, whereas managed solutions are used for distribution. These are explained further later in this chapter, in the section “Best Practices When Working with Solutions.”

Each component on an unmanaged solution has some properties, called managed properties, that depend on the component type selected. These properties enable you to specify the ability you want to give to the end users when the solution is exported as managed and then imported to another organization.

Figure 22.47 shows the managed properties you can set on a custom entity when the Managed Properties button is clicked.

Image

FIGURE 22.47 Managed properties.

If you set the first option, Can Be Customized, to False, all the other options are disabled. Notice that by default any customization you make will have this option set to True, which means any person who implements your solution can make further customization, so it is a good idea to change these values if you want to protect your customization.

For each solution component, you can perform some functions that depend on the component type. For example, you can create new entities from the solution form, new option sets, new security roles, new processes, new reports, new templates, new dashboards, new web resources, new connection roles, and new field security profiles. But you cannot create new client extensions, plug-ins, SDK message processing steps, or service endpoints.

Plug-ins

If you want to include a plug-in in a solution, you must create the plug-in first in Visual Studio and then register it with the Plug-in Registration Tool.

Image Refer to CHAPTER 25, “Plug-ins,” for details on working with plug-ins.

After you successfully register a plug-in, you can go to the solution form, click the Plug-in Assemblies node, and click the Add Existing button to include the plug-in on your solution (see Figure 22.48).

Image

FIGURE 22.48 Adding plug-ins to a solution.


Tip

On the Plug-in Assembly tab, you see the button How to Register Assemblies. It takes you to the MSDN website, to a detailed walkthrough about how to register plug-ins.


Keep in mind that plug-ins don’t support managed properties, and with managed properties, the Add Required Components button doesn’t work. If a plug-in refers to any entity that is missing from the solution, you have to add it manually.

When you add a plug-in to a solution, you don’t necessarily add all the steps you registered. If you only add the plug-in, export the solution, and implement your package on another CRM 2016 organization, the plug-in won’t work as expected because there wasn’t a step registered for the plug-in. This means you have to also include the steps you want to include on your solution right after adding the plug-in to the solution. To add the steps, you need to go to the solution form, click the Sdk Message Processing Step node, and then click the Add Existing button. Then select the steps you want to register, as shown in Figure 22.49.

Image

FIGURE 22.49 Adding SDK message processing steps to a solution.

When adding the steps, you are also asked to include the required components associated with the steps. For example, if you have a step created for the Create event of the Account entity, you should include the Account entity in your solution.

Best Practices When Working with Solutions

Although every Dynamics CRM organization has a default solution from which to start making customizations, I recommend making a backup of this solution by exporting it before you start making any customizations. Then you can customize a fresh CRM deployment. Keep in mind that any customization you make inside a custom solution will also be included on the default solution, as will any change you make on existing system entities.


Note

It is a good practice to start making any customizations in a new custom solution so that they can be easily managed in the future. If you want to customize a system entity such as Account, you can do it by adding the entity to a custom solution.


To customize a system, follow these steps:

1. Open your custom solution and ensure that the Components node is selected in the left navigation area (see Figure 22.50).

Image

FIGURE 22.50 A solution with Components selected.

2. Click the Add Existing button and select Entity (see Figure 22.51).

Image

FIGURE 22.51 Adding an existing entity.

3. Select the entity you want to add—in this case, Account (see Figure 22.52).

Image

FIGURE 22.52 Selecting the existing Account entity.

4. Click OK to add the entity assets (see Figure 22.53).

Image

FIGURE 22.53 Selecting entity assets to include in a solution for the Account entity.

Image For more information on the entity assets, SEE the section of “Solution Enhancements,” later in this chapter.

5. Check the Add All Assets check box and click Finish to add the entity. If prompted, and add any required/missing components. You see the entity with all the assets added to the solution.

You can now customize the Account entity by working with it directly from this solution. When you install this solution in another instance of Microsoft Dynamics CRM 2016, the customizations made will be affected on the new instance.

Solution Enhancements

Solutions have been really improved in Dynamics CRM 2016. Prior this version, every system entity you included on a solution included all the related subcomponents (also called entity assets), which made it difficult to manage and prevent overriding when importing solutions on the target organization.

With Dynamics CRM 2016, you can now select what entity assets you want to include in a solution. You can select from the following asset types:

Image Forms

Image Views

Image Charts

Image Fields

Image Keys

Image 1:N relationships

Image N:1 relationships

Image N:N relationships

Image Messages

Image Business rules

Image Hierarchy settings

Image Dashboards

So when you add an existing system entity to a solution, you are asked to select the entity assets you want to include on your solution, as shown in Figure 22.54 for the Lead entity.

Image

FIGURE 22.54 Selecting entity assets to include in a solution.

With this solution enhancement, you can now include a custom form you created on the Lead entity without having to add all the other relationships, forms, fields, or any other asset detailed before. This produces smaller solutions, which is especially important when you export them. (You will see how to export solutions in the next section.) It also prevents errors when you import a solution along with third-party solutions that might involve the same system entities.

If you include a system entity on a solution and include only a few assets, and then later you need to add another asset, you can do so without having to remove the system entity. You can do this by selecting the entity and clicking the Add Subcomponents button.

Exporting Solutions

You can export solutions in two different package types:

Image Unmanaged—The unmanaged option enables developers to maintain backups of the customizations; it is possible to modify unmanaged packages when applying them to another environment. Note that when you remove unmanaged solutions, the new customizations are not removed; to remove customizations, you must remove them manually by going to the default solution.

Image Managed—If you would like to distribute a solution, you should export the solution as managed so that people can’t make any customizations to the package. This gives you to control over your customizations, which is important for troubleshooting as well as control of intellectual property (IP).


Caution

Before exporting a solution, be sure to include the Site Map on the solution because it isn’t added automatically by the entities you added or created. You can add the Site Map by going to the Client Extensions node and clicking Add Existing > Site Map.


Follow these steps to export your solution:

1. Open the solution you want to export and click the Export Solution button. The Export Solution Wizard opens, suggesting that you publish all customizations before continuing (see Figure 22.55).

Image

FIGURE 22.55 Export Solution Wizard.

2. Click the Publish All Customizations button if necessary and then click Next. If prompted, include any missing required components that your solution might require and then click Next.

3. In the next screen, select the settings you want to export. The available settings are Auto-numbering, Calendar, Customization, Email Tracking, General, Marketing, Outlook Synchronization, Relationship Roles, ISV Config, and Sales (see Figure 22.56). Click Next when you’re finished making selections.

Image

FIGURE 22.56 Export settings.


Caution

Notice that when you remove the solution, these settings won’t be removed from the organization where you implemented this solution, even if you export the solution as managed.


4. Set the package type to either Unmanaged or Managed (see Figure 22.57). Click Export button, and you are asked to download the exported solution. Notice that by default the name includes the solution name, the version, and the suffix managed, if you selected a managed package type.

Image

FIGURE 22.57 Selecting the package type.


Note

Using a managed solution is a good way to distribute packages for ISV and also for Microsoft partners to avoid allowing customers to mess with any customization whose functionality can be broken (as happened in previous versions of Dynamics CRM) and also to protect the copyright of the solution. For example, users can’t export or customize a managed solution they have installed.


If you expand the compressed file you downloaded, after the import you see that it contains the following files and folders (see Figure 22.58), assuming you have exported a solution that has all these components:

Image WebResources folder

Image Workflows folder

Image Reports

Image PluginAssemblies

Image [Content_Types] XML file

Image Customizations XML file

Image Solution XML file

Image

FIGURE 22.58 Expanded solution file.

The number of folders depends on the type of components you added to the solution. If you added reports, you see them inside the Reports folder. If your solution doesn’t include any reports, however, this folder doesn’t exist.

It is important to maintain the solution version properly because this number is not automatically incremented every time you export the solution. You are responsible for incrementing this number on each export before publishing a new version to the public.

One consideration regarding versioning is that versions have four numbers, separated by dots, in the format A.B.C.D:

Image A—Major version number

Image B—Minor version number

Image C—Build number

Image D—Revision number

Use the first two numbers when you add new features to a solution and the last two numbers when you fix bugs or make improvements on existing features.

Importing Solutions

To import a solution to another organization, complete the following steps:

1. Go to Settings > Customization > Solutions.

2. Click Import. You see the dialog shown in Figure 22.59.

Image

FIGURE 22.59 Importing a solution.

3. Click Browse, locate the package zip file on your local hard drive, and then click Next. You now see the screen shown in Figure 22.60.

Image

FIGURE 22.60 Solution information.

4. Optionally, you can check the solution package details by clicking the View Solution Package Details button. You can then see the detailed contents of the package, as shown in Figure 22.61.

Image

FIGURE 22.61 Solution package details.

5. Click Close to close the Solution Details dialog and then click Import. You see the import options from which you can activate the processes and plug-in SDK messages (see Figure 22.62).

Image

FIGURE 22.62 Import options.


Note

The option to activate the processes and plug-in SDK messages, as shown in Figure 22.62, is shown only if the solution contains plug-ins or processes.



Tip

If your solution includes plug-ins and SDK message processing steps, it is important that you check the Activate Any Processes check box and then enable any SDK message processing steps included in the solution when prompted during import so that the plug-in steps will be registered successfully.


6. Click Import to import the solution. This process might take some time, depending on the customizations and assemblies included in the package. When the import finishes, you are presented with a screen showing the details (see Figure 22.63).

Image

FIGURE 22.63 Import solution details.

7. Publish the solution by clicking Publish All Customizations.


Tip

The Publish All Customizations option appears only if you are importing an unmanaged solution. If you import a managed solution, you don’t see this button, as managed solutions are published automatically.



Caution

If you don’t have sufficient permissions and the solution you are importing contains plug-ins that are not configured with sandbox isolation (as required for CRM Online), you get an error.


After importing the solution, you can download the log file, which is an XML file that can be viewed easily in Microsoft Excel. In case of any error, a user should send this file to the solution provider.

If you imported a solution that contains plug-ins and SDK message processing steps and you didn’t check the Activate Any Processes check box and the Enable Any SDK Message Processing Steps Included in the Solution check box, you can activate them later, but you will have to do that in the solution, so activate them at this point in time. When you open the solution and go to the Sdk Message Processing Step node, you can then activate or deactivate any step you want to register on the plug-in assemblies installed by the managed solutions (see Figure 22.64).

Image

FIGURE 22.64 Activating or deactivating SDK message processing steps.

All the functions that are on the solution’s user interface (UI) are also available on the API and the SDK, so you can automate the creation of solutions dynamically as well as manage the solutions from an external application. This can be useful, for example, for automating the deployment of testing environments.


Note

Microsoft does not recommend using solutions such as ASP.NET, Silverlight, or a Windows Forms application to package custom application deployments that run outside the CRM environment because they only consume the CRM resources through the Windows Communication Foundation (WCF) web services. For those applications, you should use the old way of packaging and create custom installers; you can generate these installers by using tools such as InstallShield or Package Deployer, as discussed later in this chapter.


It is a good practice to add jQuery scripts as a web resource on a solution if you are going to use jQuery on your form events. To add jQuery on your solution, download the most current version from http://jquery.com/download, go to Web Resources, and click New. Then enter the name and display name, select the type to script (JScript), and locate the jQuery file you downloaded (see Figure 22.65).

Image

FIGURE 22.65 Creating a web resource for jQuery.

You can add the backslash character (/) in the Name field to simulate virtual directories. For example, Figure 22.66 shows the Scripts folder being used.

Image

FIGURE 22.66 Adding jQuery with a custom virtual path.

Once you create this web resource, you can use jQuery on any form event.


Caution

You cannot import a managed solution into an organization that has a solution with the same name but in an unmanaged state. If you try to do that, you will see an error. If you want to test the managed package in this case, you need to import it into another organization.


Removing Solutions

After you import a custom managed solution to an organization that contains custom entities and you create records for those custom entities, CRM deletes all the records and SQL tables when you delete the managed solution. You are asked to confirm this before proceeding with the deletion operation, as shown in Figure 22.67.

Image

FIGURE 22.67 Confirming the deletion.

It is always recommended that you make a backup of the SQL Server database (if you’re working with an On-Premises version of CRM) or export the custom entities’ records to an Excel file before deleting a solution. Deleting the solution cleans the CRM database by removing all the tables and views that were created by the managed solution entities. It is important to understand this, especially if you are going to try a third-party solution on a production environment because after playing with it you may want to remove it from the CRM system.

However, if you remove a custom unmanaged solution, the SQL tables and data of the custom entities are not removed from the database.


Tip

Remember the following when removing solutions:

Image Managed solutions—All customizations applied are removed, as is all data.

Image Unmanaged solutions—The solution record is removed; however, tables, views, and data remain in the default solution.


Cloning a Patch

New to Dynamics CRM 2016 is the ability to clone a patch. This is helpful when you don’t want to distribute the entire solution if you only need to provide a patch to the customer for a single component. For example, if you have a big solution that includes a lot of components, when the customer finds a bug or an issue that must be fixed, you can distribute a patch to the customer that contains only the components you altered to fix that problem.

When you click the Clone to Patch button, you are asked to change the build and/or revision numbers of the version of the solution (see Figure 22.68).

Image

FIGURE 22.68 Cloning a patch.

This dialog automatically suggests the next recommended version number, so if your solution is version number 1.0.0.0, the dialog suggests that you use the version number 1.0.1.0. If this is what you want to do, just click Save.

A new clean solution is created for the patch, and you can add the updated components there. You can then export the patch and import it to the target organization, as shown in Figure 22.69.

Image

FIGURE 22.69 Solution patch.

After you have cloned a patch for a solution, you can no longer export the original solution as long as solution patches exist. If you try to export the original solution, you get the warning message shown in Figure 22.70.

Image

FIGURE 22.70 Exporting a parent solution is not allowed after you clone a patch.

Cloning Solutions

New to Dynamics CRM 2016 is the ability to clone a solution. You can only clone unmanaged solutions. When you click the Clone to Solution button on the command bar, you are asked to change the major and/or minor number of the version of the solution (see Figure 22.71).

Image

FIGURE 22.71 Cloning a Solution.

This dialog automatically suggests the next recommended version number, so if your solution is version number 1.0.0.0, the dialog suggests that you use the version number 1.1.0.0. If this is what you want to do, just click Save. This action merges the patches with the original solution, producing a new single release of your solution.


Caution

Clone to Solution removes any patch solution you have created. Therefore, before you use this option, make sure to export the patches and have a backup of the exported patch solution files.


Patching Solutions

New to Dynamics CRM 2016 is the ability to patch a solution. By clicking the Apply Solution Upgrade button on the command bar, you can import a patch for a solution. This is possible only when you import a solution that was previously cloned and it is a major or minor version upgrade.

After you import the new solution, you are asked to apply the solution upgrades in the last step of the Import Solution Wizard, as shown in Figure 22.72.

Image

FIGURE 22.72 Applying solution upgrades.

All the existing previous solutions and patches are combined on the new installed/imported solution, and you end up with a single reference to the latest version of the solution in the target organization.

Working with Multiple Solutions

CRM implementations are likely to contain multiple custom solutions. In addition to having multiple solutions containing custom modifications in their CRM systems, organizations typically have multiple vendor (ISV) solutions as well.

When importing solutions, you should consider some things related to the predefined system entities. If you import a solution that includes a customized form of any system entity—for example, the Contact entity—this solution could be applied (or “layered”) by removing some fields and tabs on the existing Contact entity. These customizations will take precedence over any other solution that includes the same Contact entity without any customization. So, if you need to include the system Contact entity in a solution, you need to make at least one customization to the form so that you can be sure all the needed fields will not be overwritten by another solution.


Tip

When working on a custom solution that will require a system entity, it is a good idea to consider adding new custom roles and creating new forms associated with these new security roles. Doing so helps you avoid having other solutions overlap with your solution customizations. If you do this, users need to use your custom roles to have a better experience with your solution.


Entity Forms Security

One important consideration when working with solutions that contain custom entities is the security configuration for the necessary roles. By default, when you create a custom entity, only the System Administrator and System Customizer roles are granted permission to use the custom entity. You are responsible for giving the right permissions to any other role (such as the Customer Representative role) so that users who have that role can work with the custom entity you included in the solution.

To configure security roles, open a solution and complete the following steps:

1. Navigate to Components > Entities > your custom entity > Forms and select the form (see Figure 22.73).

Image

FIGURE 22.73 Customization of a form.

2. Click Enable Security Roles from the command bar, and the Assign Security Roles dialog appears (see Figure 22.74).

Image

FIGURE 22.74 Assigning security role information.

3. Click the role you want to configure (in this example, the Customer Service Representative role) to open the Security Role editor page.

4. Go to the Custom Entities tab. You will see that all the solution custom entities are there, with no permissions set, as shown for the Project row in Figure 22.75.

Image

FIGURE 22.75 The Custom Entities tab.

5. Grant the permissions to the operations you want to have them by clicking the circles. Notice that if you click the entity name, you configure all the operations in the entire row at the same time (see Figure 22.76).

Image

FIGURE 22.76 The Custom Entities tab with permissions set.

Because CRM 2016 allows you to have different forms for each security role, you can create new forms with different fields and assign them to different roles. For example, you might have sensitive fields on an entity that you would like to hide to a lower role, such as the Customer Service Representative role. You can easily do this by creating a new form and designing it to show only the fields this user role should see.

Figure 22.77 shows an entity with more than one main form created to be used by different roles.

Image

FIGURE 22.77 Entity with multiple main forms.

If you have a user who has more than one role assigned and there is one form created for each role, you need to be sure to set the order in which these forms are displayed for such cases (see Figure 22.78). You can do this by selecting Form Order > Main Form Set.

Image

FIGURE 22.78 Setting the form order.

Because the first form on this list is displayed on the first role match, you might consider reordering the forms so that the more detailed form is displayed first.


Tip

If you include a customized role as part of your solution that is derived from one of the standard roles (such as Customer Service Representative), you may accidently override the end user role configurations already set for that role. This is why creating a custom role is always recommended.


Migrating Customizations from Previous Versions

Because some custom code will not work when you upgrade from Dynamics CRM 2013/2015, it is recommended that you run the Custom Code Validation Tool that Microsoft supplies.


Note

You can find the Custom Code Validation Tool by searching Microsoft.com for “Custom Code Validation Tool” or by going directly to www.microsoft.com/en-us/download/details.aspx?id=30151.


The tool focuses primarily on custom JavaScript, and it gives output that allows you to address scripts that don’t work in CRM 2016 prior to running an upgrade.

Third-Party and Marketplace Solutions

The Microsoft Dynamics Marketplace is a website where Microsoft partners and ISVs publish their solutions so that users of CRM can easily find and install them in their environments.

For ISVs

The Microsoft Dynamics Marketplace is located at http://dynamics-crm.pinpoint.microsoft.com (see Figure 22.79), and the AppSource is located at: https://appsource.microsoft.com.

Image

FIGURE 22.79 Microsoft Dynamics Marketplace.

The AppSource is brand new and will replace the Dynamics Marketplace by the end of 2016, however its functionality and purpose are the same.

If you are an ISV and want to have your solution in the Microsoft Dynamics Marketplace, you first have to be listed in Microsoft Pinpoint. To do that, your company needs to be a Microsoft partner. Microsoft partners can list software solutions using the Solution Profiler tool and can also be listed in the Microsoft Pinpoint website.

There are two types of product registrations: For Microsoft CRM applications, go to the Microsoft Platform Ready website and test the application using free tools, and for Microsoft ERP applications, get the solution tested and certified with the CfMD (Certified for Microsoft Dynamics) certification.

The Microsoft Dynamics Marketplace helps you find the right customers by exposing your application to Microsoft Dynamics users from around the world, who will be able to download your application from this site and also connect with your company.

For Customers

If you are a customer, the Microsoft Dynamics Marketplace will help you discover and try custom solutions developed by third-party vendors that are be of interest and that might prevent you from having to develop a new custom solution from scratch. Because the solutions that are available in the Marketplace are verified and certified, you can feel confident installing them and not worry about system stability.

Developer Resources

You can access the developer resources by going to the CRM web interface and navigating to Settings > Customizations (see Figure 22.80).

Image

FIGURE 22.80 Customizations page.

If you click the Developer Resources link, you are directed to a page that contains all the information necessary for development with Dynamics CRM 2016, as shown in Figure 22.81.

Image

FIGURE 22.81 Developer Resources page.

The Getting Started Section provides several links:

Image Developer Center—This takes you to https://msdn.microsoft.com/dynamics/crm/crmdevelopercenter.aspx.

Image Developer Forums—This takes you to https://community.dynamics.com/crm/f/117?pi51520=0&category=Development%20%2F%20Customization%20%2F%20SDK.

Image SDK NuGet Packages—This takes you to www.nuget.org/profiles/crmsdk.

Image SDK Download—This takes you to www.microsoft.com/en-us/download/details.aspx?id=50032.

Image Sample Code—This takes you to https://msdn.microsoft.com/dynamics/crm/samplecode.

Image Developer Overview—This takes you to https://msdn.microsoft.com/library/gg334635.aspx (for Dynamics CRM On-Premises, the link takes you to https://msdn.microsoft.com/en-us/library/gg309589.aspx).

Configuration Migration

CRM Configuration Migration is a tool you can find in the SDK in the SDKToolsConfigurationMigration folder. This tool helps ensure that the import and export of entity records necessary for your solution run properly.

When you run this tool by executing the DataMigrationUtility.exe file, you see Figure 22.82.

Image

FIGURE 22.82 CRM Configuration Migration Start screen.

With this tool you can choose any of these options:

Image Create Schema

Image Export Data

Image Import Data

The following sections explain these operations in detail.

Create Schema

Before you can try to export data, you need to create a schema that defines the entities and fields you want your exported data to have. To do this, click the Create Schema option button and then click Continue. You need to provide your CRM connection information. Once you enter the CRM connection information and click the Login button, you see a page where you can select the solution file, as shown in Figure 22.83.

Image

FIGURE 22.83 CRM Configuration Migration export details.

When you select a solution and an entity, the tool filters only the entities included in the selected solution.

Select the fields of the entity selected and click the Add Fields button to include them in your schema. You can then change the entity and select fields for that entity. You can repeat this as many times as needed. For this example, select the account name and account number of the Account entity and first and last names and Account ID of the Contact entity, as shown in see Figure 22.84.

Image

FIGURE 22.84 CRM Configuration Migration selected schema fields.

When you are done adding fields, click the Save and Export button. Select the file location where you want to store the schema and click OK. After the schema is saved, you are prompted about exporting the data (see Figure 22.85).

Image

FIGURE 22.85 Export confirmation.

If you click Yes, you are directed to the Export Data Wizard.

Export Data

To export data, you can click the Export Data option button on the main start screen of the Configuration Migration tool and then click Continue. Enter the CRM connection information and click Login. Then provide the input schema file that you created earlier and the output zip data file that will contains the records (see Figure 22.86).

Image

FIGURE 22.86 Exporting Data.

Click the Export Data button to continue. When the export data process is completed, you see the results in the lower part of the screen, as shown in Figure 22.87.

Image

FIGURE 22.87 Data export completed.

Click Exit to go back to the main startup screen.

Import Data

To import the data you exported before, you can click the Import Data option button on the main start screen of the Configuration Migration tool and click Continue. Enter the CRM connection information and click Login. Then provide the input zip data file that will contains the records (the one you created using the Export Data function), as shown in Figure 22.88.

Image

FIGURE 22.88 Importing data.

Click Import Data to continue. When the import data process is complete, you will see the results in the lower part of the screen.

Click Exit to go back to the main startup screen.

Package Deployer

Package Deployer is a tool you can find in the SDK, in the SDKToolsPackageDeployer folder. This tool helps in the deployment of solutions as well as the creation of the records your solution needs to run properly.

Sometimes installing a solution by importing it is not enough. For your product to work properly, you need to create some records that the solution relies on. This is where you use the Package Deployer tool.

You run this tool by executing the PackageDeployer.exe file. When you click Continue on the welcome screen, if you don’t have any package created, you see the error shown in Figure 22.89, and the tool exits.

Image

FIGURE 22.89 “No import packages found” error.


Note

The Unified Service Desk (USD) uses the Package Deployer to install the USD solutions. For more information about this, refer to Chapter 13, “The Unified Service Desk (USD)”.


Create Package

To create a package, you need to use Visual Studio 2013 or 2015, and use the .NET Framework 4.5.2. In this example, you will use Visual Studio 2015, and you will create a new CRM package project type (see Figure 22.90).

Image

FIGURE 22.90 CRM Package Visual Studio project.


Note

To create this project type, you must first install CRMSDKTemplates.vsix, which you find in the SDKTemplates folder.


Each CRM package contains the following components:

Image CRM solution files, which you export from the CRM web interface, as explained earlier in this chapter

Image Compressed data files, which you can create using the Configuration Migration tool, as explained earlier in this chapter

Image Custom code you can write to be fired on events during the package installation process

Image HTML content you can display when the package is deployed

Edit the ImportConfig.xml file to include the CRM solutions you want to be imported by the package and include the data files you want to be imported.

Here is an example of the ImportConfig.xml file:

<?xml version="1.0" encoding="utf-16"?>
<configdatastorage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   installsampledata="true"
                   waitforsampledatatoinstall="true"
                   agentdesktopzipfile=""
                               agentdesktopexename=""
                   crmmigdataimportfile="data.zip">
  <solutions>
    <configsolutionfile solutionpackagefilename="solutionFile_1_0_0_0.zip" />
  </solutions>
</configdatastorage>

Put the data.zip file and solutionFile_1_0_0_0.zip in the PkgFolder. Change Build Action to Content and set Copy to Output Directory to Copy Always (see Figure 22.91).

Image

FIGURE 22.91 Copy always content files.

Build the solution and copy all the files generated by the output under the bin debug folder to the folder where you have the Package Deployer (SDKToolsPackageDeployer). Do not replace any existing file; just copy the new ones.

Package Deployment

After you created a package with Visual Studio and copy the files to the SDKToolsPackageDeployer folder, you can start the PackageDeployer.exe application again.

When the start page appears, click Continue, enter your CRM connection details, and click Login. You see the first custom welcome screen (the one that you can customize in your package that is located in the PkgFolderContenten-usWelcomeHtmlHTMLDefault.htm folder), as shown in Figure 22.92.

Image

FIGURE 22.92 Custom welcome screen.

Click Next, and the next screen asks you to confirm details before starting the deployment (see Figure 22.93).

Image

FIGURE 22.93 Ready to Install screen.

Click Next to continue, and a first initial validation occurs before the deployment starts (see Figure 22.94).

Image

FIGURE 22.94 Validation screen.

Click Next, and the deployment process starts. It might take some time, depending on the solutions and data you included in the package.

If any error occurs during the deployment process, you can click the View Log link to open the log file, where you can see more details about the error.

Click Next again, and you see the custom installation complete screen (which you can customize by editing the PkgFolderContenten-usEndHtmlHTMLDefault.htm file).

Click Finish to close the Package Deployer tool.

Themes

New to Dynamics CRM 2016 is the ability to brand the Dynamics CRM user interface with your company logo and also change some basic styles, such as using the colors of your company. You do this type of branding by using themes.

To access the themes configuration, select Settings > Customizations. There, when you click the Themes option, you will see the list of available themes.

To create a new theme, click New. As shown in Figure 22.95, enter a name for the new theme.

Image

FIGURE 22.95 New theme.


Tip

It is recommended that you copy the default theme before creating a new theme and not modify the default theme. This way, you can make the changes more quickly, and you can restore the default theme easily if you need it in the future.


As you can see, there are a lot of empty fields here. This is why it’s better to copy the default theme than to try to create a theme from scratch. To do that, go back to the list of themes, select the default theme, and click the Clone button.

Open the copy of the theme you cloned and make your edits. These are the styles you can change:

Image Logo

Image Logo Tooltip

Image Navigation Bar Color

Image Navigation Bar Shelf Color

Image Header Color

Image Global Link Color

Image Selected Link Effect

Image Hover Link Effect

Image Process Control Color

Image Default Entity Color

Image Default Custom Entity Color

Image Control Shade

Image Control Border

The logo size must be 400px (width) by 50px (height).

To add a logo for your company, you must create a web resource, so you click the lookup icon at the end of the Logo field and click +New, as shown in Figure 22.96.

Image

FIGURE 22.96 Editing a logo.

You now see a Web Resource window. In it, enter the name for your web resource and a display name and select PNG, GIF, or JPG from the Type drop-down. Then browse to a logo file on your local computer, as shown in Figure 22.97.

Image

FIGURE 22.97 Selecting a logo web resource.

Click Save and then click Publish. Close the Web Resource dialog and find the logo you just created. Click the Preview button to preview your changes before publishing the logo to the rest of the users.

If you like how it looks, then go back to Settings > Customizations > Themes, select the theme, and click Publish Theme in the top command bar. If you don’t like how it looks, click the Exit Preview button and make any additional changes prior to publishing.


Note

You can have only one theme active for the entire organization. Dynamics CRM 2016 still doesn’t support custom theming to different OUs or roles.


Working with the SDK

The SDK includes help files, documentation, binary tools, and code samples that give developers the capability to extend and understand advanced Microsoft Dynamics CRM customizations. By advanced customizations, I refer to all customizations that can’t be done through the standard CRM user interfaces, such as the ones you saw earlier in this chapter. To develop these advanced customizations, you need a tool such as Visual Studio 2015, along with solid knowledge and understanding of .NET development and programming in languages such as C# or Visual Basic .NET and JavaScript.


Note

The SDK does not usually come with the Dynamics CRM media, so you must download it from Microsoft. You can find it by searching for “CRM 2016 SDK” at Microsoft.com or by navigating to http://msdn.microsoft.com/dynamics/crm.


Advanced customizations can include the following:

Image Server programming

Image Advanced workflow development

Image For details about workflow development, SEE CHAPTER 26, “Process Development.”

Image Plug-in development

Image Client programming

Image Report development

Image Advanced report development with SQL Server Reporting Services (SSRS)

Image For details about report development, SEE CHAPTER 16, “Reporting and Dashboards.”


Tip

The main SDK help file, CrmSdk2016.chm, contains detailed documentation about all these topics.


Summary

This chapter looks at the CRM entity model, the attribute types you can use to add new fields to the entity forms, the alternate keys you can create, and the relationships between the entities (1:N, N:1, or N:N). In this chapter you have learned how to make some basic customizations, such as adding tabs, sections, and controls to forms. You have used and reviewed the IFRAME control and also added menus and controls to the toolbar by using the Site Map, command bars, and ISV Config files. You have learned how to use JavaScript events exposed by the form controls, such as OnLoad and OnSave, to extend the forms and the OnChange event for fields. In this chapter you have also seen how to easily debug scripts and how to import and export customizations.

This chapter describes how to customize Microsoft Dynamics CRM for deployment, support, and distribution by using solution packages. It reviews the differences between managed and unmanaged solutions and looks at the Microsoft Dynamics Marketplace, where ISVs can promote their solutions and customers can find solutions.

This chapter also reviews some of the SDK tools you can use, such as the Configuration Migration to manage import data and the Package Deployer tool to create packages you can distribute. The chapter wraps up by quickly covering the SDK and its uses.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset