Walkthrough: Capturing the GUID Values of Records Selected in a Grid

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

This walkthrough describes how to capture the GUID values of records displayed in an entity view.

During this walkthrough you will learn how to:

  • Confirm that you will be able to export and use custom menus and toolbars.
  • Configure ISV.Config to display a modal dialog window
  • Create an HTML page which captures the window.dialogArguments and displays the GUID ID properties of the selected records.
  • Test the HTML page to confirm that the window is capturing the GUID values of the selected records.

Note   This example will only work when the HTML page is on the same domain as the CRM Server due to security features in Internet Explorer to address cross-site scripting concerns.

Confirm You Can Export and Use Custom Menus and Toolbars.

Before you can continue in this walkthrough you must verify the following:

  • That Custom Menus and toolbars have been enabled for your Microsoft Dynamics CRM installation.
  • That your user account is associated with a security role that has the ISV Extensions privilege and that you have the necessary privileges to export and import customizations.

Enable Custom menus and toolbars

Custom Menus and toolbars is a system setting. Custom Menus and toolbars are turned off by default.

  1. In the Microsoft Dynamics CRM Web application, click Settings.
  2. Click Administration and then System Settings.
  3. Click the Customization tab and select the clients that you want to display custom buttons and menu items. For the purposes of this walkthrough, only the Web application must be enabled.
  4. Click OK.

Confirm that your user account is able to use custom menus and toolbars.

  1. In the Microsoft Dynamics CRM Web application, click Settings.

  2. Click Administration and then Users.

  3. Locate your user account and click Roles.

  4. Open the security role(s) associated with your user account.

  5. On the Customization tab verify that you have Organization level access to the following privileges located under Miscellaneous Privileges.

    ISV Extensions

    Export Customizations

    Import Customizations

Note   If you do not have the privileges necessary to view or update security roles work with your system administrator to associate your user account a security role that contains the necessary privileges.

Configure ISV.Config

This example will configure a button on the Account entity grid. There are three steps to this process:

  • Export ISV.Config
  • Configure the button for the Account entity grid
  • Import ISV.Config.
  1. In the Microsoft Dynamics CRM Web application, click Settings.

  2. Click Customization and then Export Customizations.

  3. Scroll down the list of Exportable items and select ISV.Config.

  4. Click Export Selected Customizations.

  5. Save the customizations.zip file.

  6. Extract the customizations.xml file from the customizations.zip file.

  7. Open the customizations.xml file using Visual Studio or any text editor, such as notepad.

  8. The default ISV.Config includes a number of sample extension control configurations. You can modify one of the existing extension controls or configure a new one.

  9. Locate the following node in the default ISV.Config:

    ImportExportXml/IsvConfig/configuration/Entities/Entity name="account"/Grid/MenuBar/Buttons
  10. Configure a button element as a child of the Buttons element using this XML:

          <Title LCID="1033" Text="Get GUIDS" />
          <ToolTip LCID="1033" Text="Get GUIDS for selected records" />

The key elements are the Url and WinMode attributes to the Button element.

Important   The URL must point to a page on the same domain as the Microsoft Dynamics CRM Server.

This example will place the test.htm page in the ISV directory located in the Microsoft Dynamics CRM web site installation path. The WinMode attribute must be set to either 1 or 2 so that a dialog window is opened rather than a standard window. Window.dialogarguments is only available for the two dialog windows (modal and modeless).

  1. Save customization.xml file with the changes you have made.
  2. In the Microsoft Dynamics CRM Web application, click Settings.
  3. Click Customization and then Import Customizations.
  4. Browse to the customization.xml file you have saved and click Upload.
  5. After the file has loaded, click Import Selected Customizations.

Create the HTML Page to Capture the GUIDs

This page will use a JScript function in the onload event of the page to detect whether the window.dialogarguments is available and simply display the GUID values in the page. In a solution that takes actions using the GUID values, these values would be passed to another application.

  1. Create a file named test.htm in the ISV folder of your Microsoft Dynamics CRM Web application.

  2. Use the following code in the page:

          <title>GUIDs for records seleced in Grid</title>
          <script type="text/jscript">
             function listselecteditems()
                var placeholder = document.getElementById("test");
                var sGUIDValues = "";
                var selectedValues;
                //Make sure window.dialogArguments is available.
                if (window.dialogArguments)
                   selectedValues = new Array(window.dialogArguments.length -1);
                   placeholder.innerText = "window.dialogArguments is not available.";
                selectedValues = window.dialogArguments;
                if (selectedValues != null)
                   for (i=0; i < selectedValues.length; i++)
                      sGUIDValues += selectedValues[i] +"\n";
                   placeholder.innerText = sGUIDValues;
                   placeholder.innerText = "No records were selected.";
       <body onload="listselecteditems()">
       <div id="test"></div>

The listselecteditems function is called when the page loads. If window.dialogArguments doesn't exist, the innerText property of a placeholder div element in the pages is updated with a message. If window.dialogArguments does exist, a new array is created based on the length of window.dialogArguments. Then a for loop iterates through the items in the array and the GUID values are appended to a string. The innerText value of the placeholder div element is updated with the string value.

Save the test.htm page to the ISV folder.

Test the Button

  1. In the Microsoft Dynamics CRM Web application, click Workplace.

  2. Click Accounts.

    You should see the button you configured in the toolbar.

    Get GUIDs in account toolbar

  3. Select a number of accounts in the view and then click the Get Guids button. The test.htm page should open and display the GUIDs for the selected accounts.

    GUIDs from selected accounts

© 2010 Microsoft Corporation. All rights reserved.