CRM 2011 Web Resource Part 1: Using HTML Web Resource

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>CRM 2011 HTML Web Resource </title>
    <!-- including the 'ClientGlobalContext.js.asp'
     -- which gives the context information-->
    <script src="ClientGlobalContext.js.aspx">
    </script>
     <!-- including the minified version of jquery-->
    <script type="text/javascript" src="new_jquery_1.4.1.min.js"></script>
    <script language="javascript">
        function getAllData() {
            var serverUrl;
            var ODataPath;
            var userid;
            var userRole;
            var OrgName;
            var context = GetGlobalContext();
            serverUrl = context.getServerUrl();
            ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
            userid = context.getUserId();
            userRole = context.getUserRoles();
            OrgName = context.getOrgUniqueName();
            Text1.Title = serverUrl;
            Text2.Title = userid;
            Text3.Title = userRole;
            Text4.Title = OrgName;
            Text1.value = serverUrl;
            Text2.value = userid;
            Text3.value = userRole;
            Text4.value = OrgName;
        }
    </script>
</head>
<body onload="getAllData();">
    <p>ServerURL:&nbsp;
        <input id="Text1" type="text" /></p>
    <p>User ID &nbsp;
        <input id="Text2" type="text" /></p>
    <p>User Role &nbsp;
        <input id="Text3" type="text" /></p>
    <p>Oraganization &nbsp;
        <input id="Text4" type="text" /></p>
 </body>
</html>

In this post we will see

  1. how to add HTML web resource to CRM 2011 Form
  2. How to get the Context in the HTML web resource
  3. How to use the GetGlobalContext function,

Steps to Follow

  1. Create a new solution
  2. Add a new Entity called –’TestforHTMLWebresource’
  3. Add  a Web Resource  with the name’Jquery1.4.1’ minified version as shown in the screenshot
  4. image
  5. Add another HTML page as a webresource  but with the following Code.

  6. Save and Publish the HTML webresource,
  7. open the Entity form
  8. insert the above created HTML web resource
  9. Publish all the customizations and Export the Solution
  10. Reimport the solution
  11. Refresh the browser.
  12. You can observe  the  HTML Webresource showing the Following Values
    1. server Url
    2. userId
    3. User Role
    4. Organization.
  13. The solution appears as detailed in the below screenshot
  14. image
  15. The complete solution file can be downloaded from here
Advertisements

One Response to CRM 2011 Web Resource Part 1: Using HTML Web Resource

  1. roscode says:

    Does this also work when embedding an HTML web resource into a dashboard? I keep getting an error saying that “GetGlobalContext” is null or undefined.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: