Form customizations

Exclusive offer: get 50% off this eBook here
Microsoft Dynamics CRM 2011 Cookbook

Microsoft Dynamics CRM 2011 Cookbook — Save 50%

Includes over 75 incredible recipes for deploying, configuring, and customizing your CRM application with this book and ebook

$35.99    $18.00
by Dipankar Bhattacharya | August 2013 | CRM Enterprise Articles Microsoft

Forms enable the display of the entity data to the users. Here in this article by Dipankar Bhattacharya, author of Microsoft Dynamics CRM 2011 Cookbook, we will delve into the recipes for creating and customizing entity form. Forms are the most commonly used platform to display data inside the Dynamics CRM system. Hence, forms should be carefully designed and implemented.

So, in this article by Dipankar Bhattacharya author of Instant Parallel Processing with Gearman, we will discuss the following recipes:

  • Creating and customizing an entity main form
  • Controlling form behavior using JScript
  • Customizing the process-driven form (Dynamics CRM 2011 Online only)
  • Creating and customizing the mobile form
  • Configuring a form to be role-based
  • Creating and customizing a public view
  • Customizing search criteria for a Quick Find view
  • Creating a user's personal view
  • Deactivating or deleting a user's personal view

(For more resources related to this topic, see here.)

Forms are probably the most important visual element of the Dynamics CRM 2011 interface. To find the underlying data in every entity record, the user has to open the form. Dynamics CRM 2011 supports two types of forms:

  • The main form : Dynamics CRM 2011 uses this form to allow the user to enter and view data within the Dynamics CRM 2011 web user interface as well as the Dynamics CRM 2011 within Microsoft Outlook interface.

    One main form per entity exists by default. However, multiple main forms can be created for an entity. Dynamics CRM 2011 supports role-based forms, which means separate forms can be visible depending on the security roles of the current user. Usually, multiple main forms are created when role-based forms have to be supported.

  • The mobile form : Dynamics CRM 2011 uses this form when a user is accessing CRM from a mobile device that is compatible with HTML 4.0 using a URL such as <CRM_server> /m, where <CRM_server> is the path of Microsoft Dynamics CRM 2011 Server. A separate form for mobile devices is useful considering the limited space usually available on a mobile screen. A mobile form does not store data on a mobile device.

    If users try to access Dynamics CRM 2011 from an unsupported browser, they will be redirected to the mobile form.

    The following table outlines the browsers supported by Microsoft Dynamics CRM 2011:

    Browser

    Version / other requirements

    Internet Explorer

    IE7 (only for the on-premises version)

    IE 8, IE9

    IE10 (desktop mode only)

    Mozilla Firefox

    Latest publicly released version running on Windows 8, Windows 7, Windows Vista, or Windows XP

    Google Chrome

    Latest publicly released version running on Windows 8, Windows 7, Windows Vista, or Windows XP

    Apple Safari

    Latest publicly released version running on Mac OS X 10.7 (Lion) or 10.8 (Mountain Lion)

    Detailed information about supported browsers can be found at http://technet.microsoft.com/en-us/library/hh699710.aspx.

Dynamics CRM 2011 also supports special variants of the main form, as follows:

  • The read-optimized form : Dynamics CRM 2011 has another type of form called the read-optimized form. Introduced in Update Rollup 7, this form is designed for the fast display of a record by disabling the ribbon and form scripts. This form displays the record in the read-only mode. Read-optimized forms are disabled by default and can be enabled by going to System | Administration | System Settings | Customization | Form Mode .

    Update Rollup 12 has introduced the following changes in read-optimized forms:

    • The navigation pane for read-optimized forms is now enabled and the navigation pane can be expanded or collapsed.
    • Support for web resources has been added. A new setting in the web resource properties, called Show this Web Resources in Read Optimized form , has been added. This setting must be enabled for the web resources to display in the read-optimized form. If the web resource depends on form resources, which are not available in a read-optimized form, we should not display it.

    Read-optimized forms honor all field-level security and role-based form definitions. If an entity has more than one form enabled, the read-optimized form uses the form that the user last used.

  • The process-driven form : The December 2012 Service Update (Polaris update) of Dynamics CRM 2011 has introduced an enhanced read-optimized form, commonly known as the process-driven form for the Account, Contact, Lead, Opportunity, and Case entities. This new type of form is very useful, especially for touch devices, as the new form is designed to contain everything in one form; there is no need to open multiple pop ups. However, this new form type cannot be used for any entity other than the entities listed above.

    For the Account, Contact, Lead, Opportunity, and Case entities, in addition to the information form, there will be a new form with the same name as that of the entity. The <entity name> form will always display using the updated presentation, regardless of the settings for read-optimized forms. However, if read-optimized forms are enabled for the organization, the information form will also display using the updated presentation.

    These new forms are not available in an on-premises deployment of Microsoft Dynamics CRM 2011.

Form editor

We need to use a form editor to customize a form within Dynamics CRM 2011. The form layout definition is actually stored as an XML file called Form Xml in the SystemForm entity. The customization.xml file exported with an unmanaged solution contains the definition of the entity forms.

Creating and customizing an entity main form

Almost all the business entities have a customizable main form. The Activity entity does not have any form and some entity forms such as the Case Resolution entity form are not customizable. When a custom entity is created, one main and one mobile form are added automatically. In this recipe, we will focus our discussion on how to customize a main form.

Getting ready

Dynamics CRM 2011 introduced a flexible layout for form design. The following diagram outlines the typical main form layout within the Dynamics CRM 2011 system:

The major visible components of a standard main form are as follows:

  • Ribbon : This is the top area of the form. We cannot customize this using the form editor.
  • Entity icon : This displays the Icon for Entity Form icon of the entity. It is a 32 x 32 pixel image and can be updated for an entity. 
  • Header and footer : The header and footer are two read-only areas of the form layout. These two sections remain static when a user scrolls through the form data displayed by the various tabs and sections. So any data that is required to be available to the user irrespective of any scrolling, can be included in these sections.
  • Form selector : When an entity has multiple forms and the current user's security role has access to more than one form, the form selector is displayed. The user can use the form selector to choose a form from multiple forms available to them.
  • Navigation : This section allows users to navigate to related records of the current record. We can add, modify, delete, or reorganize the link to the related entity records using the form editor. We can also include links to URLs or web resources by adding navigation links using the form editor.
  • Form assistant : It helps when we set values for lookup fields. Dynamics CRM 2011 has introduced improved capabilities to filter data returned in the lookup dialog. Hence, the form assistant is no longer useful; the form assistant has been turned off for all except the following three entity forms:
    • Case
    • Product
    • Service activity
  • Tabs and sections : Tabs and sections allow grouping and laying out of controls in a form. A tab can contain multiple sections. Each form can have a maximum of 100 tabs. Tabs have a vertical collapse/expand feature.

We will now take a look at the various form-body elements that can be added or associated with an entity form:

  • Field : Each field represents an attribute of the entity. A field can be added to a form using the form editor and the form editor allows us to add the same field multiple times in a form. Each instance of a field in a form is known as a control . The appearance and behavior of a control is driven by the type and formatting options of the attribute as well as display and formatting properties set on the control, using the form editor.
  • Tab and section : As previously discussed, tabs and sections are used for grouping the controls in the form. A tab can contain multiple sections within it. Each tab or section can be assigned a name. We can choose to display the name of the tab or section on the form or include a separator line at the top of the tab or section, underneath the name.

    A tab can have one column or two columns; when two columns are specified, the width of each column is a percentage of the width of the tab. A section, on the other hand, may have up to four columns and we can control the width available for control labels to be displayed in the section as well as how labels for controls in the section should be aligned.

  • Spacer : The Spacer element provides extra space between fields and controls in the form. This is used to improve the control layout in a section.
  • Sub-Grid : Sub-Grid allows us to display a list of records, charts, or both.

    The first four subgrids can be populated with data in a form when it loads. If more than four subgrids exist on a form, the remaining subgrids require some user or form script action to retrieve data. This is for performance optimization.

  • IFRAME : This control provides the HTML iFrame element in the form. Using the control, we can host another web page within the Dynamics CRM 2011 entity form. The form editor provides the ability to set regular iFrame properties along with properties specific to Dynamics CRM 2011.
  • Web Resource : This control displays a form-enabled web resource to be displayed on the page. A form-enabled web resource includes a web page (HTML), image (JPG, PNG, GIF, ICO), or Silverlight (XAP) resource. The web resource contents are hosted within Dynamics CRM 2011.
  • Notes : If the entity uses notes and attachments, we can add the Notes control into the form. This control can only be added if the entity has Notes enabled in the entity definition.
  • Navigation Link : This control is available only within the Navigation section of the form. This control allows us to add a link to an external URL or web resource.

How to do it…

In this recipe, we will first discuss how to create a new main form and then discuss the form-customization options. The customization steps can be carried out on any main form.

The entity main form can be customized by carrying out the following tasks:

  • Editing tabs
  • Editing sections
  • Editing fields
  • Editing header and footer
  • Adding subgrids
  • Adding iFrames
  • Adding web resources
  • Editing the Navigation area
  • Editing form properties
  • Making the form non-customizable

In this recipe, we will discuss all the previously stated tasks one after the other. Please follow these steps to customize the main form for an entity:

  1. Log in to the Dynamics CRM 2011 system as a system administrator or with a relevant security role.
  2. Navigate to Settings | Customizations | Solutions and change the view to Unmanaged Solutions , if not already selected.
  3. Then double-click on the unmanaged solution to open it.
  4. On the expanded Solution page, navigate to Components | Entities | <Entity> | Forms .

The next step is to create a new main form; this can be done in two ways. We will discuss both of these here:

  • Creating an entirely new main form : Go to New | Main Form in the actions toolbar. This will create a new form by copying the existing main form. When the new form pops up, click on the save button to save the form.

  • Creating a new form from an existing form : Open the existing form by double-clicking on it. When the form launches, click on Save As in the top ribbon. When the Save As -- Webpage Dialog window pops up, provide data for the Name and Description fields of the new form. Finally, click on the OK button to save the new form as shown in the following screenshot:

Any newly created main form will be assigned only to the system administrator and system customizer security roles by default.

To customize a main form, open the form by double-clicking on it in the forms list.

The next step is to discuss the editing of tabs in the form. Tabs are collapsible controls that can contain section controls. The following two points will demonstrate adding a new tab and editing tab properties:

  • Adding a new tab in the form : Click on Body in the form ribbon and then click on the Insert tab in the form. In the Insert tab, under the Tab group, select One Column to create a one-column tab, or Two Columns to create a two-column tab:

    If we add a tab, Dynamics CRM 2011 will automatically add a section for each column.

    To remove any control in an entity form, use the Delete key on the keyboard. Alternatively, the Remove button in the ribbon can also be used.

  • Editing tab properties : Select the tab control and then click on the Change Properties button in the form ribbon. The Tab Properties page will open with the following properties being modifiable:

    Tab property

    Description

    Under the Display tab

    Name

    The unique name of the tab.

    Label

    The display label for this tab. This text will appear on the form.

    Show the label of this tab on the Form

    This determines whether the label defined for this tab will be displayed on the form. Select this option to enable the display of the tab's label on the form.

    Expand this tab by default

    If selected, the tab control will be displayed in expanded mode by default.

    Visible by default

    If selected, the tab control will be visible by default in the form.

    Under the Formatting tab

    Select tab layout

    Choose between One Column and Two Columns  to define the layout of the tab.

    Column 1 width

    If the Two Columns option is selected in the tab layout, we can specify the width of column 1 as a percentage.

    Column 2 width

    If the Two Columns option is selected in the tab layout, we can specify the width of column 2 as a percentage.

    The Events properties

     

    Scripts libraries can be linked to the tab. The scripts functions will be called on the TabStateChange event.

Next we will see the editing of a section in a tab. A section contains fields in the form. The following two sections will demonstrate adding a section in a form and editing the section's properties:

  • Adding a section in the form : Select the tab control where the new section is to be added and then click on the Insert tab in the form ribbon. Thereafter, click on One Column , Two Columns , Three Columns , or Four Columns under the Section group depending on whether a section with one, two, three, or four columns is to be added.
  • Editing section properties : Select the section control and then click on the Change Properties button in the form ribbon. The Section Properties page will open and the following properties will be modifiable:

    Section property

    Description

    Under the Display tab

    Name

    The unique name of the tab.

    Label

    The display label for this tab. This text will appear on the form.

    Show the label of this section on the Form

    This determines whether the label defined for this section will be displayed on the form. Select this option to enable the display of the section's label on the form.

    Show a line at top of the section

    If selected, a divider line will be displayed underneath the name of the section.

    Width

    Specify the width of the label area of the fields in this field. The width must be set between 50 and 250 pixels.

    Visible by default

    If selected, the section control will be visible by default on the form.

    Lock the section of the Form

    If selected, the section would be locked in the form.

    Under the Formatting tab

    Layout

    Choose from among One Column, Two Columns, Three Columns, and Four Columns to define the layout of the section control.

    Field label alignment

    Select between the Left and Right alignments for the field labels in the section control.

Next we will take a look at editing a field in the section:

  • Adding a field in a section : Select the section where the field has to be added. Thereafter, find the field in the right-hand side Field Explorer pane. By default, the Field Explorer pane displays all unused fields in the form. If we want to add a field that is already used in the form, uncheck the Only show unused fields checkbox as shown in the following screenshot:

    After selecting the field in Field Explorer , move the field by pressing the left mouse button and drop the field in the intended column of the section. The red line on top of the column indicates that the column has been selected. Now drop the field on the selected column.

  • Editing field properties : To edit the form-level properties of the field, select the field and then click on the Change Properties button in the form ribbon. Then the Field Properties pop up will open and the following properties can be modified:

    Field property

    Description

    Under the Display tab

    Label

    Here you can edit the display name of the field on the form. By default, the display name of the field will be displayed there, which can be edited to provide a new display name for the field on the form.

    Display Label on the form

    This determines whether the display name of the field is to be displayed in the form.

    Field is read-only

    This determines whether a field is to be read-only for the users in the form.

    Lock the field on the form

    This determines whether the field is to be locked on the form.

    Visible by default

    This determines the default visibility of the control in the form.

    Under the Formatting tab

    Layout

    This determines the width of this field on the form. The width of a field depends on the layout settings of the section it is in.

    The Details properties

     

    This tab displays the details of the field definition. Click on the Edit button to modify those properties of the field definition that can be modified.

    The Event properties

     

    Script libraries can be linked to the tab. The scripts' functions will be called on the OnChange event.

    If the field is of type Lookup (N:1 relationship with another entity), then there exists an additional set of properties in the Field Properties list. These properties can be set to save the user's time, find the appropriate parent record, or to restrict the user to select among a subset of records in the parent entity. The following form-level properties of the lookup field can be edited:

    Property name

    Description

    Turn off automatic resolutions in the field

    If this setting is disabled (not selected) and if a user enters a partial value for the lookup field and tabs away, Dynamics CRM 2011 will try to autopopulate the lookup field.

    Disable most recently used items for this field

    If this setting is disabled (not selected), Dynamics CRM 2011 will automatically provide a list of recently selected values for the user to choose from.

    This property is not supported for process-driven forms of Microsoft Dynamics CRM 2011 Online.

    Related Record Filtering

    This setting provides a way to limit the list of records that the user can choose from. The list under the Only show records where heading displays all the potential relationships that can be used to filter this lookup. Once a record is selected, the list under the Contains  heading will display all relationships that connect the related entity (selected in the first list) to the target entity.

    Select the Allow users to turn off filter checkbox to provide users with the option to turn off the filter defined here. This makes it possible for them to view a wider range of records.

    Additional properties

    This setting controls how much search flexibility the user will have in terms of changing among various views and searching the record with a search box.

    Select the Display Search Box in lookup dialog checkbox if you want a search box to be available in the lookup.

    In the Default View list, select the default view for which results will be displayed in the lookup.

    Finally, choose the views we want users to have access to in the lookup, using the View Selector list.

  • Adding a new entity field and then adding it to the form : A new field can also be created and then added to the entity from the form. To create a new field, click on the New Field button at the bottom of the Field Explorer pane. This will launch the new field pop up. 

Next we will delve into editing headers and footers.

To edit the header or footer of the form, click on the Header or Footer button in the form ribbon and the section will be focused automatically. Then click on Change Properties in the ribbon. The Header Properties or Footer Properties page will pop up and we can edit the following settings:

Header/footer property

Description

Under the Display tab

Width

Specify the width field label area here. The width must be set between 50 and 250 pixels.

Lock the section of the Form

This setting is selected by default and cannot be modified. This setting determines whether the section would be locked in the form or not.

Under the Formatting tab

Layout

Here you can choose from among One Column,  Two Columns, Three Columns, and Four Columns to define the layout of the header/footer control.

Field Label Alignment

Select from the Left (default), Right, or Center alignment for the field labels in the header/footer control.

Field Label Position

Select between Side (default) and Top to specify whether the field label in this section will be on the left-hand side or above the field.

Fields can be added to the header or footer controls in the same way they are added in any section control in the form.

Next we will look at how to add subgrids. The Sub-Grid control displays related entity records in the form body, using the following steps:

  1. Select the section control where the subgrid is to be added in the form.
  2. Then click on the Sub-Grid button under the Insert tab in the form ribbon. This will bring up the List or Chart Properties page, where we can specify the following properties of a subgrid:

    Subgrid property

    Description

    Under the Display tab

    Name

    The unique name of the subgrid control.

    Label

    The display text of the subgrid. This text will be displayed on the form.

    Display label on the Form

    Select to confirm that the Label text will be displayed on the form.

    Data Source

    This specifies the primary data source of the subgrid.

    The Records list allows us to select between Only Related Records (to set only entities having a relationship to the current entity) and All Record Types (to set all available entities).

    We can choose the related entity from the Entity list. This list content will vary based on the earlier list's selection.

    The Default View list allows us to choose which view is to be displayed in the subgrid.

    Display Search Box

    Select this setting to display the search box in the subgrid.

    Display Index

    Select this setting to display the alphabetic index record selector in the subgrid.

    This property is not supported for process-driven forms of Microsoft Dynamics CRM 2011 Online.

    View Selector

    Select this setting to display the view selector in the subgrid.

    This property is not supported for process-driven forms of Microsoft Dynamics CRM 2011 Online.

    Chart Options

    Select whether to display a chart selector along with a default chart or show only a specified chart in place of the subgrid.

    This property is not supported for process-driven forms of Microsoft Dynamics CRM 2011 Online.

    Under the Formatting tab

    Layout

    Choose from among One Column, Two Columns, Three Columns, and Four Columns to define the layout of the subgrid control.

    Number of Rows

    Select the maximum number of rows to be displayed in the subgrid control. The number of rows has to be between 2 and 250.

    Automatically expand to use available space

    Select this setting to enable automatic expansion of the subgrid to use available space in the form.

iFrames or Inline Frames are HTML documents embedded inside the Dynamics CRM entity form. The following steps will guide you through adding an iFrame in the form:

  1. Select the section control where the iFrame is to be added in the form.
  2. Then click on the IFRAME button under the Insert tab in the form ribbon. This will bring up the Add an IFRAME page, where we can specify the following properties of an iFrame:

iFrame property

Description

Under the General tab

Name

The unique name of the iFrame control.

URL

The URL of the HTML document to be displayed in the iFrame control.

Pass record object-type code and unique identifier as parameters

Select this option to pass contextual information entity object-type code and the record's unique identifier to the iFrame.

Read more about this in the How it works... section of this recipe.

Label

Here, specify the display text for the iFrame.

Display label on the Form

Select this setting to display the label on the form.

Restrict cross-frame scripting, where supported

This checkbox is selected by default. We can remove this restriction only if we are certain that the HTML document/site we are using as the target of the iFrame can be trusted.

Visible by default

Select this setting to make the iFrame visible by default on the form.

Under the Formatting tab

Layout

Choose from among One Column, Two Columns, Three Columns, and Four Columns to define the layout of the iFrame control.

Number of Rows

Select the maximum number of rows the iFrame control occupies on the form. The number of rows has to be between 1 and 40.

Automatically expand to use available space

Select this setting to enable automatic expansion of the iFrame control to use the available space in the form.

Scrolling

Select the scrolling option for the iFrame content display.

Display Border

Specify whether a border for the iFrame control is to be displayed.

Web resources represent files that can be used to extend the Microsoft Dynamics CRM 2011 web application, such as HTML files, Image files, JScript library, and Silverlight applications. The following steps can be used to add a web resource in the form:

  1. Select the section control where the web resource is to be added in the form.

  2. Then click on the Web Resource button under the Insert tab in the form ribbon. This will bring up the Add Web Resource page, where we can specify the following properties of a web resource:

    Web resource property

    Description

    Under the General tab

    Web Resource

    Lookup to find a form-enabled web resource.

    Name

    The unique name for the web resource.

    Label

    Specify the display text for the web resource here.

    Display label on the Form

    Select this setting to display the label on the form.

    Visibility by default

    Select this setting to make the web resource visible by default on the form.

    Show this web resource in Read-Optimized Form

    Select this setting if the web resource is to be displayed in the read-optimized form.

    Under the Formatting tab

    Layout

    Choose from among One Column, Two Columns, Three Columns, and Four Columns to define the layout of the web resource control.

    Number of Rows

    Select the maximum number of rows the web resource control occupies on the form. The number of rows has to be between 1 and 40.

    Automatically expand to use available space

    Select this setting to enable automatic expansion of the web resource control to use the available space in the form.

    Scrolling

    Select the scrolling option for the web resource content display.

    Display Border

    Specify here whether a border for the web resource control is to be displayed.

    The Dependencies properties

     

    Select the fields from the Available fields list that are required by the web resource, and then click on the (add selected records) button to move the selected fields to the Dependent fields list.

The navigation area displays entities that are related to the current entity. Each relationship has a Label property and in this navigation section this Label property is displayed by default. However, the display name for the related entity can be changed. This display name does not update the Label property of the relationship. In order to edit the navigation area, perform the following steps:

  1. Select the Navigation button in the form ribbon.
  2. The navigation section will be enabled. Then click on any relationship label and select Change Properties to edit the display text. This will bring up the Relationship Properties page.
  3. Modify the Label field here.

Next we will edit the form properties; in order to do this, click on the Form Properties button in the form ribbon and the Form Properties page will pop up. The following properties can be edited there:

Form property

Description

The Event properties

 

Add or remove the JScript libraries that will be available for the form or field events.

Under the Display tab

Form Name

The display name for the form. Modify this to rename the form.

Description

Specify a description for this form here.

Show navigation items

Select this setting to display the page navigation in the form.

The Parameters properties

 

Add query string parameters to be passed to the form. Click on the green plus sign to add a query string. We have to provide a Name value and select a Type value of the query string parameter.

The Non- Event Dependencies properties

 

Select the fields from the Available fields list that are required by any external, non-event scripts, and then click on the (add selected records) button to move the selected fields to the Dependent fields list. These fields will not be removable from the form.

Lastly, making a form non-customizable restricts any future customization of the form. Therefore, to make a form non-customizable, perform the following steps:

  1. Select the Managed Properties button in the form ribbon.
  2. The Managed Properties of System Form: Form web page dialog will pop up. In this page, mark Customizable as False .

After making any changes to an entity form, the form has to be saved and published. Use the Publish button in the form ribbon to publish the changes.

How it works…

Web resources and iFrames are not displayed using the Microsoft Dynamics CRM 2011 for Outlook reading pane, but iFrames are displayed in read-optimized forms. When the Pass record object-type code and unique identifier as parameters setting is enabled, iFrames allow the form to pass the following contextual parameters to itself:

Parameter name

Description

typename

The name of the entity.

type

This takes in the entity type code, which is an integer value to uniquely identify an entity in a specific organization.

Id

A GUID that represents a record.

orgname

The organization's name.

userlcid

The user's language code.

orglcid

The organization's language code.

The list of entity type codes can be found at http://msdn.microsoft.com/en-us/library/gg328086.aspx. The key points about entity type codes are as follows:

  • Type codes below 10,000 are reserved for out-of-the-box entities.
  • Custom entities will have a type code greater than or equal to 10,000.
  • Custom entities' type codes might change during solution import. Hence the type codes of a custom entity might be different in the development and test environments.
  • The entity codes are stored in the Dynamics CRM database and can be retrieved from the EntityView table of the <OrganizationName>_MSCRM database.
Microsoft Dynamics CRM 2011 Cookbook Includes over 75 incredible recipes for deploying, configuring, and customizing your CRM application with this book and ebook
Published: June 2013
eBook Price: $35.99
Book Price: $59.99
See more
Select your format and quantity:

Controlling form behavior using JScript

Form scripting allows us to perform a variety of actions such as enforcing custom field validation and automation and displaying values for calculated fields within a form in the Microsoft Dynamics CRM 2011 system. Most of the time, performing actions on data that is available on the client side offers better performance than using methods, which require data to be saved by the user, and then performing actions on the web server.

Dynamics CRM 2011 forms support scripts written using JScript and can be associated with the following two form events:

  • OnLoad: This event is triggered when the form is loaded. This event is usually used to initialize the form for use.
  • OnSave: This event is triggered when a user tries to save the form data. This event is usually used for data validation. Scripts associated with this event can cancel the save before it is sent back to the server.

Additionally, each field in a Dynamics CRM 2011 form provides access to the OnChange event. This event is triggered whenever a user changes data in the field or clicks a different form element (meaning, the field loses focus). This event can be used to validate the field data, perform calculations to change other fields, or implement dynamic pick lists (drop-down lists).

Update Rollup 12 and December 2012 Service Update (Polaris update) have introduced the following exceptions to the behavior of triggering the OnChange event for the Two-Option fields that are formatted to use radio buttons or checkboxes:

  • If a Two-Option field is formatted to use radio buttons, the OnChange event occurs immediately without requiring that field to lose focus.
  • If a Two-Option field is formatted to use checkboxes, the OnChange event occurs immediately without requiring that field to lose focus, except when the browser is Internet Explorer 7 or 8.

The OnChange event does not fire if the field value is modified programmatically using the setValue method. To handle this scenario, we can use the fireOnChange method in the code.

How to do it…

Please perform the following steps to add scripts in a Dynamics CRM form:

  1. Log in to the Dynamics CRM 2011 system as a system administrator or with a relevant security role.
  2. Navigate to Settings | Customizations | Solutions and change the view to Unmanaged Solutions , if not already selected.
  3. Then double-click on the unmanaged solution to open it.
  4. In the expanded solution page, navigate to Components | Entities | <Entity> | Forms . Double-click on the form where the script is to be used.
  5. When the form designer opens up, click on Form Properties in the form ribbon.
  6. In the Form Properties dialog, click on the Add button in the actions toolbar of the Form Libraries section.
  7. The Look Up Record view will open up, and from this view the web resources can be added to the form library. Select a JScript web resource from the grid, if the JScript web resource is already added.

    Otherwise, click on the New button present at the bottom-left side of the view to add a new web resource. The Web Resource: New page will appear. In this page, provide the following information:

    Web resource property

    Value to be provided

    Under the General tab

    Name

    The schema name of the script-type web resource

    Display Name

    The display name of the web resource. Optional but recommended

    Description

    Optionally enter some descriptive text about the web resource

    Under the Content tab

    Type

    Select Script (JScript) from the drop-down list

    Language

    Select the language of the web resource from the drop-down list

    Uploaded File

    Click on the Browse button if you wish to upload the already saved JScript file

    Then click on the Text Editor button associated with Type . This will bring up the Edit Content dialog. Add the JScript methods in the Source section.

  8. After adding the JScript to the web resource, click on the Save button in the Web Resource: New form ribbon. Thereafter, publish this web resource by clicking the Publish button in the ribbon. Finally, close the form.
  9. Click on OK in the Look Up Record dialog. Now we can find the web resource added to the form libraries.
  10. Below Form Libraries , in the Event Handlers section, choose the following options:
    • Control : Select Form to add a script to form events. Select any form fields to add a script to the field event.
    • Event : If the Form control was selected, then we have to select between the OnLoad and OnSave events depending on which event we want to add our script to.
  11. Thereafter, click on the Add button in the Event Handlers section. The Handler Properties window will pop up. In the Details tab, provide the following inputs:
    • Library : Select an item from the form library
    • Function : Select the JScript method to be called from the selected library
    • Enabled : Select the Enabled checkbox to make the JScript method available to be called by a field event
    • Pass execution context as first parameter : Select this option if the execution context is to be passed as the first parameter
    • Comma separated list of parameters that will be passed to the function : A comma separated list of parameters to be passed to the JScript method
  12. Then, in the Dependencies tab, add the fields using the (add selected records) button, which is used by the current script, from the Available fields list to Dependent fields .

    Up to 50 event handlers per event can be defined. Each handler is executed in the order that it is displayed on the Events tab of the form element's properties dialog box.

  13. Finally, save and publish the form.
  14. The script can be tested in three modes of a form: create, update, and read-only. In the form designer ribbon, click on Preview and then select Create Form , Update Form , or Read-Only Form .

How it works…

Scripts are added to a form or form fields to implement behaviors that are not available out of the box with Dynamics CRM 2011. Microsoft Dynamics CRM 2011 recommends the use of the Xrm.Page object model methods to access the form elements. Though for backward compatibility Dynamics CRM 2011 still supports crmForm, this support is expected to be withdrawn in the next major release of Microsoft Dynamics CRM.

Update Rollup 12 and December 2012 Service Update (Polaris update) support browsers other than Internet Explorer. Hence it is required that form scripts should also support W3C standards so that the script can also work in other browsers. This requires removal of dependencies on HTML components (HTC ) that are specific to Internet Explorer. To identify potential issues with custom JScript libraries, Microsoft has released a tool known as Microsoft Dynamics CRM 2011 Custom Code Validation Tool . It is highly recommended to validate any custom JScript using this tool before applying them. The tool can be downloaded from the following URL:

http://www.microsoft.com/en-us/download/details.aspx?id=30151

However, to continue support for HTC, Update Rollup 12 and December 2012 Service Update (Polaris update) have both introduced an organization-level setting called Include HTC support in Microsoft Dynamics CRM Forms . For Microsoft Dynamics CRM 2011 Online organizations, the setting is turned "off" by default. But for on-premises organizations, the setting is turned "on" by default.

To modify the value of this setting, navigate to Settings | System | System Settings | Customization and then select or unselect the Include HTC support in Microsoft Dynamics CRM Forms setting.

Enabling HTC support will not allow the newer versions of Internet Explorer to provide the best possible performance. Internet Explorer 10 does not support HTC components. Support for HTC will be removed in the next major release of Microsoft Dynamics CRM.

Modifying Microsoft Dynamics CRM 2011 application pages or forms using jQuery is not supported. The only supported use of jQuery in the Microsoft Dynamics CRM 2011 is the use of the jQuery.ajax method to retrieve data from the REST endpoint.

There's more…

In addition to the events discussed in this recipe, Microsoft Dynamics CRM 2011 supports two more events:

  • TabStateChange: This event is triggered when a tab is expanded or collapsed
  • OnReadyStateComplete: This event is triggered when the contents of any iFrame have completed loading

Customizing the process-driven form (Dynamics CRM 2011 Online only)

In this recipe, we will discuss how to customize the process-driven forms available in Microsoft Dynamics CRM 2011 Online.

Getting ready

The process-driven forms introduced in the Polaris update of Microsoft Dynamics CRM 2011 uses most of the elements described in the standard form. However, there are a few changes as shown in the following diagram:

The following are the changes introduced in this new type of form:

  • Command bar : A process-driven form does not have any ribbon; instead, it has a fixed set of commands for each entity and these are known as command bar controls . Some important features of command-bar controls are as follows:
    • These controls are record states (Active /Inactive ) and are permission-aware (security-role access). These commands do not render if the user does not have proper permissions and they also display a different set of commands in different states.
    • Command controls cannot be extended. Any ribbon customization done will not be applied in these process-driven forms.
    • Command bar controls are not solution-aware.

    The command bar provides a Switch to Classic option that displays the record in the edit-form mode.

  • Header fields : The header fields in this process-driven form are displayed differently, but defined in the form in the same way as that of the standard main form.

    Unlike a standard form, a process-driven form's header fields allow editing.

    However, a process-driven form can only display a maximum of 4 fields in the header area. Hence, if the header contains more than one row, additional header fields will not be visible in this mode. Header fields, being part of the form, are solution-aware.

  • Business processes : This is a newly introduced feature in Lead, Opportunity, and Case entity forms. These controls cannot be viewed in the form editor. The existing business processes can be edited from the process-driven form itself; however, new business processes cannot be created. These controls are not solution-aware.
  • Inline edit controls : Entity fields added to a process-driven form will be displayed in a new way. A field has to be selected to make it active for edit and thus prevents accidental modifications. Inline edit controls are solution-aware. A Bing Map control is also added as part of inline edit controls.
  • Collaboration controls : Collaboration controls rendered in a process-driven form display the following tabs:
    • Posts (Activity Feed/Yammer)
    • Activities
    • Notes

    These controls are user-permission-aware and display based on the security role of the user.

    The form editor will only display the Notes control, which can be removed or added to the form. The other two controls are only viewed in the process-driven form and cannot be customized.

  • Subgrids : The process-driven form displays subgrids with a new lighter look and feel and provides some inline editing capabilities. The records in a subgrid can be deleted inline. Subgrids are part of the form and hence are solution-aware.
  • The auto-save control : The auto-save control appears on the bottom-right corner of the form and it automatically saves the record after record creation. Some important properties of this control are as follows:
    • After the first edit, the auto-save fires every 30 seconds
    • Auto-save retrieves any changes and displays them in the form without reloading it
    • Only data that has been changed since the last save is saved
    • The field currently being edited is not saved
    • Closing the form automatically saves the record
    • Command bar actions such as New , Create , or Qualify also save the record

Each time an auto-save fires, it is actually an update to the record. Hence, any workflow or plugin registered against the Update event will trigger. Therefore, the workflow or plugin should be developed and registered in a way that it is triggered on the changing of some specific field values and not just on any field update.

How to do it…

The following controls can be modified using the same steps as those used during the creation of the main form:

  • Tabs and sections
  • Fields
  • Header and footer
  • Subgrids
  • iFrames
  • Web resources
  • The navigation area
  • Form properties

The SOCIAL PANE control, which displays Posts , Activities , and Notes , is locked in the form and cannot be customized or removed.

However, process-driven forms have a few additional controls that can be customized:

  • Bing Map
  • Lync or Skype
  • Yammer

In this recipe, we will discuss all the stated tasks one after the other. For process-driven form customization, the Form Editor application can also be invoked from the command bar of any entity record with the new form.

Please perform the following steps to customize the process-driven form for an entity. Firstly, you need to log in to the Dynamics CRM 2011 system as a system administrator or with a relevant security role.

We will now take a look at configuring the Bing Map display. The Bing Map control displayed in the process-driven form is locked in the form and cannot be modified or removed. The map is linked to display Address1 and this setting too cannot be altered.

  • We can disable or enable Bing Maps by navigating to Settings | System | Administration | System Settings | General and configuring the Show Bing Maps on forms setting.

Process-driven forms support Skype and Lync calls from the Dynamics CRM 2011 form itself, using the Click to Call feature:

  • To enable the Lync call feature :
    1. We have to ensure that the Lync client is installed on the local machine and the Lync add-on is enabled in the Internet Explorer. Go to Tools | Manage add-ons in Internet Explorer. The following screenshot is what you will see:

    2. Then navigate to Settings | System | Administration | System Settings | General and set the Select provider for Click to call setting to Lync .
  • To enable the Skype call feature :
    1. We have to ensure that the Skype client is installed on the local machine. Then navigate to Settings | System | Administration | System Settings | General .
    2. Set the Select provider for Click to call setting to Skype .

If the Lync/Skype add-on recognizes the number format, it inserts a telephone icon (for Lync) / Skype icon (for Skype) before the phone number. When the add-on is disabled or not installed, a hyperlink on the phone number will be visible.

To make calls from Microsoft Dynamics CRM 2011 Online, any phone number must be of the <country/region code><area code><number> format. However, during data entry, a user may not enter the phone number in the stated format. Hence, Dynamics CRM 2011 Online provides a system-wide setting to enable country/region code prefixing.

This setting can be enabled by navigating to Settings | System | Administration | System Settings | General and selecting the Enable country/region code prefixing checkbox, and then specifying the country/region code, such as +91, in Country/Region Code Prefix .

This organization-wide setting can be overridden by the user's preferred setting. But if a user specifies a different country/region prefix in the record, it will override the user-level and organization-level prefixes.

Lastly, we will look into configuring Yammer. The Polaris update has introduced Yammer integration with Dynamics CRM 2011 Online.

  1. To configure Yammer, navigate to Settings | System | Administration | Yammer Configuration .
  2. On the Yammer Disclaimer page, click on Continue .
  3. The Yammer configuration page will appear. If you are already logged into Yammer, you will find the enterprise Yammer network along with the groups already populated. Otherwise, we have to log on to Yammer by clicking on the Authorize Microsoft Dynamics CRM Online to connect to Yammer link.
  4. Select the appropriate Yammer Group ID value and security level as shown in the following screenshot:

  5. The next screen will display a confirmation message (Congratulations, your system is configured for Yammer! ) about the Yammer integration with Dynamics CRM 2011.
  6. Thereafter, we have to enable the rule configurations for Yammer. Navigate to Settings | System | Administration | Post Rule Configurations . Select the rule we want to enable and then click on the Enable for Yammer button in the ribbon.

Connecting to Yammer is a one-way process. After the connection is established, it cannot be undone.

How it works…

In Microsoft Dynamics CRM 2011 Online, the new process-driven forms will be displayed for Account, Contact, Lead, Opportunity, and Case entities irrespective of the read-optimized mode setting.

Some of the important features of a process-driven form are as follows:

  • Process-driven forms support web resources having the Show this Web Resources in Read Optimized form setting enabled.

    Except for the Xrm.Page.ui.getFormType method, the Xrm.Page.ui object is not available in process-driven forms. As a performance enhancement, web resources and parts of the Xrm.Page object model are loaded asynchronously for process-driven forms. As a result, if any script in the web resource depends on some Xrm.Page objects, such an object may not be available when a script runs. In addition, there is no public event to indicate that the parts of the Xrm.Page object are available. To counter this, scripts in the web resource should implement a strategy to query the Xrm.Page object to determine whether the objects to be used are available before using them.

  • Process-driven forms do not support any type of event handler to be configured in the form definition. If an event handler is applied to these forms, they will appear as edit forms.
  • The changes made to a record are saved automatically in process-driven forms. This auto-save behavior is not configurable.

The Click to Call functionality uses the skype: (for a Skype call) and tel: (for a Lync call) protocols that enable the direct call functionality for the numbers entered in the out-of-box phone number fields in Microsoft Dynamics CRM Online. When a phone number in a record is clicked, Microsoft Dynamics CRM 2011 opens Skype or Lync and dials the phone number automatically.

Skype and Lync clients and applications are not supported on iPad and other mobile devices. For the Click to Call feature, the supported Lync version is Lync 2013/2010 and the Skype version is Skype 6.0 or later.

The Yammer integration with Dynamics CRM 2011 is not available with on-premises Microsoft Dynamics CRM 2011 installations. Moreover, Yammer and activity feeds cannot be used simultaneously.

The following are a few important features of the Yammer integration:

  • User posts created via the Dynamics CRM 2011 Online user interface are stored in Yammer, not in the Dynamics CRM system.
  • Auto posts are created and stored in the Dynamics CRM system. Some auto posts are also stored in Yammer in addition to Dynamics CRM.
  • Users are followed in Yammer only, not within Dynamics CRM.
  • Objects other than the user are followed in both Dynamics CRM and Yammer. Yammer connection must be enabled before we can follow objects in Yammer.
  • If the default Yammer group for users to post from the Dynamics CRM organization is deleted in Yammer, the Yammer group association with the Dynamics CRM organization has to be changed.
  • If the Post to Yammer Activity Stream rule is set to True in Post Rules Configuration, that activity will post to Yammer.

Resources for Article :


Further resources on this subject:


Microsoft Dynamics CRM 2011 Cookbook Includes over 75 incredible recipes for deploying, configuring, and customizing your CRM application with this book and ebook
Published: June 2013
eBook Price: $35.99
Book Price: $59.99
See more
Select your format and quantity:

About the Author :


Dipankar Bhattacharya

Dipankar Bhattacharya is a Dynamics CRM consultant and Microsoft technology evangelist. He is a Certified Professional in Microsoft Dynamics CRM, the Microsoft Dynamics Sure Step methodology, and core .NET technologies, such as .NET 3.5, ADO.NET, WPF, and WCF. He has been working with Microsoft technologies for around nine years and his primary focus has been solution architecture, system integration, computer telephony integration, and data migration. Currently, he is associated with Microsoft Services Global Delivery as a Business Solution Consultant and he is working with various enterprise customers, assisting them with architecting a solution till its deployment. He has been architecting, developing, and deploying business solutions across the globe using Dynamics CRM, xRM and Customer Care Accelerator for Dynamics CRM, and so on.

Books From Packt


Microsoft Dynamics CRM 2011 New Features
Microsoft Dynamics CRM 2011 New Features

Microsoft Dynamics CRM 2011: Dashboards Cookbook
Microsoft Dynamics CRM 2011: Dashboards Cookbook

Microsoft Dynamics CRM 2011 Reporting
Microsoft Dynamics CRM 2011 Reporting

Getting Started with Microsoft Dynamics CRM 2013 and xRM Application Development
Getting Started with Microsoft Dynamics CRM 2013 and xRM Application Development

Microsoft Dynamics CRM 2011 Customization & Configuration (MB2-866) Certification Guide
Microsoft Dynamics CRM 2011 Customization & Configuration (MB2-866) Certification Guide

Microsoft Dynamics CRM 2011 Applications (MB2-868) Certification Guide
Microsoft Dynamics CRM 2011 Applications (MB2-868) Certification Guide

Microsoft Dynamics CRM 2011 Scripting Cookbook
Microsoft Dynamics CRM 2011 Scripting Cookbook

Microsoft Dynamics CRM 2011 Application Design
Microsoft Dynamics CRM 2011 Application Design


Your rating: None Average: 2 (10 votes)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
X
F
C
3
8
u
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software