Just created a simple html page to see how we can use it in CRM 2011.
The page is on account form and shows name of the account. It also accesses ClientGlobalContext.js file to show contextual information like Organization Unique Name and User Id of the user.
The html page:-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- Access the ClientGlobanContext js file src="ClientGlobalContext.js.aspx" if the html web resource doesn't follow any folder structure i.e. http://servername/orgname/WebResources/new_myHtmlWebResource src="../ClientGlobalContext.js.aspx" if the html web resource follows folder structure i.e. http://servername/orgname/WebResources/new_myfolder/myHtmlWebResource --> <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script> <script type="text/javascript"> function ContextInformation() { // accessing attributes in the form window.parent.Xrm.Page document.getElementById('td1').innerHTML = window.parent.Xrm.Page.getAttribute('name').getValue(); var context = GetGlobalContext(); // or by using window.parent.Xrm.Page.context document.getElementById('td2').innerHTML = context.getOrgUniqueName(); document.getElementById('td3').innerHTML = context.getUserId(); } </script> <title>My HTML Web Resource</title> <style type="text/css"> .style1 { width: 100%; } .style2 { width: 147px; font-weight: bold; } .style3 { width: 478px; } </style> </head> <body onload="ContextInformation();"> <table class="style1"> <tr> <td class="style2"> Account Name:-</td> <td class="style3" id="td1"> </td> <td> </td> </tr> <tr> <td class="style2"> Organization Name:-</td> <td class="style3" id="td2"> </td> <td> </td> </tr> <tr> <td class="style2"> User Id:-</td> <td class="style3" id="td3"> </td> <td> </td> </tr> </table> </body> </html>
Points to remember
Access the ClientGlobanContext js file
src=”ClientGlobalContext.js.aspx” if the html web resource doesn’t follow any folder structure
i.e. http://servername/orgname/WebResources/new_myHtmlWebResource
src=”../ClientGlobalContext.js.aspx” if the html web resource follows folder structure
i.e. http://servername/orgname/WebResources/new_myfolder/myHtmlWebResource
and using window.parent.Xrm.Page to get the reference to the Xrm.Page from the html web resource
Hope it helps.
you again were of great help to me today nishant….thank you! 🙂
LikeLike
Kya chal raha hain Kantala
LikeLike
Simple and useful. Thanks for sharing this siampl!
LikeLike
Great post 🙂
LikeLike
how do you invoke getUserId if the SL application is hosted in html web resource and not within any entity form?
LikeLike
This is not working in CRM 2015 online. can you tell me any alternative?
LikeLike