Microsoft Dynamics CRM 4.0 中列表上的按钮如果用Javascript ,怎么给js方法传选中的值。
Posted on 2012-10-24 23:50 Hamilton Tan 阅读(406) 评论(0) 编辑 收藏 举报请教一个问题,在CRM4.0 中列表上的按钮如果用Javascript 怎么给js方法传选中的值啊
如图,点击打电话,想获得选中记录的ID
答复一:可以参考CRM4.0 SDK中的例子:
Walkthrough: Capturing the GUID Values of Records Selected in a Grid
Walkthrough: Capturing the GUID Values of Records Selected in a Grid
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.
- In the Microsoft Dynamics CRM Web application, click Settings.
- Click Administration and then System Settings.
- 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.
- Click OK.
Confirm that your user account is able to use custom menus and toolbars.
- In the Microsoft Dynamics CRM Web application, click Settings.
- Click Administration and then Users.
- Locate your user account and click Roles.
- Open the security role(s) associated with your user account.
- 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.
- In the Microsoft Dynamics CRM Web application, click Settings.
- Click Customization and then Export Customizations.
- Scroll down the list of Exportable items and select ISV.Config.
- Click Export Selected Customizations.
- Save the customizations.zip file.
- Extract the customizations.xml file from the customizations.zip file.
- Open the customizations.xml file using Visual Studio or any text editor, such as notepad.
- 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.
- Locate the following node in the default ISV.Config:
ImportExportXml/IsvConfig/configuration/Entities/Entity name="account"/Grid/MenuBar/Buttons
- Configure a button element as a child of the Buttons element using this XML:
11.<Button
12. Icon="/_imgs/ico_18_debug.gif"
13. Url="/ISV/test.htm"
14. WinMode="2"
15.>
16. <Titles>
17. <Title LCID="1033" Text="Get GUIDS" />
18. </Titles>
19. <ToolTips>
20. <ToolTip LCID="1033" Text="Get GUIDS for selected records" />
21. </ToolTips>
</Button>
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).
- Save customization.xml file with the changes you have made.
- In the Microsoft Dynamics CRM Web application, click Settings.
- Click Customization and then Import Customizations.
- Browse to the customization.xml file you have saved and click Upload.
- 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.
- Create a file named test.htm in the ISV folder of your Microsoft Dynamics CRM Web application.
- Use the following code in the page:
3. <html>
4. <head>
5. <title>GUIDs for records seleced in Grid</title>
6. <script type="text/jscript">
7. function listselecteditems()
8. {
9. var placeholder = document.getElementById("test");
10. var sGUIDValues = "";
11. var selectedValues;
12. //Make sure window.dialogArguments is available.
13. if (window.dialogArguments)
14. {
15. selectedValues = new Array(window.dialogArguments.length -1);
16. }
17. else
18. {
19. placeholder.innerText = "window.dialogArguments is not available.";
20. return
21. }
22. selectedValues = window.dialogArguments;
23. if (selectedValues != null)
24. {
25. for (i=0; i < selectedValues.length; i++)
26. {
27. sGUIDValues += selectedValues[i] +"\n";
28. }
29. placeholder.innerText = sGUIDValues;
30. }
31. else
32. {
33. placeholder.innerText = "No records were selected.";
34. }
35. }
36. </script>
37. </head>
38. <body onload="listselecteditems()">
39. <div id="test"></div>
40. </body>
</html>
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
- In the Microsoft Dynamics CRM Web application, click Workplace.
- Click Accounts.
You should see the button you configured in the toolbar.
- 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.
答复二:关于视图的一些常用函数和方法:
刷新:
crmGrid.Refresh()
打印:
crmGrid.Print();
获取已选择的项的GUID集合:
getSelected("crmGrid");
获取未选择的项的GUID集合:
getNotSelected("crmGrid")
可以跟踪一些表单上的按钮事件,或看一下CRM里载入的JS,会有不少发现。