Home Programming Form customizations

Form customizations

0
2625
26 min read

(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.
    Learn Programming & Development with a Packt Subscription

    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.

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here