CRM 2011 Web Resource Part 2: How to use “ClientGlobalContext.js.aspx”

When you work with HTML web resources, There might be situations where you need data about the CRM.

“ClientGlobalContext.js.aspx”  gives  the  Context information out side of the CRM FORM.

when we do reference to the above file, what comes next is How to refer the above file., it takes some time to figure out.,

Way1: <script src="ClientGlobalContext.js.aspx"></script>  << refer like this when you use a web resource with out having folder conventions>>

Way2: <script src="../ClientGlobalContext.js.aspx"></script>   << refer like this when you use web resource with a folder like structure

For example:Web resource name  is referred as “test_/new_HTMLResource.htm”>>

Way 3: <script src="../../ClientGlobalContext.js.aspx"></script>   << refer like this if the web resource looks like this “ test_/testing1/new_HTMLResource.htm”

I hope this would help and save lot of time of yours when you start working with Web resources

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

CRM 2011: Web Resources

What are  Web Resources?

Web Resources are the Virtual files stored in Microsoft Dynamics CRM Database, and also they can be accessible using a unique URL address

Why do we use Web Resources?

Web Resources are used to extend the CRM web application which can be in the form of html, Jscript, Silverlight applications

Where can we use Web resources?

Web Resources can be used in

  1. Form Customization
  2. Sitemap
  3. Application Ribbons

What are the major Limitations for Web Resources?

  1. No Support for .ASPX pages
  2. Web Resources are Limited to Static Files or files processed by browser only.
  3. Maximum Size of the web resource is determined by Organization.MaxUploadFileSize property

Web Resource Types?

File

File extensions

Type

Web Page (HTML)

.htm, .html

1

Style Sheet (CSS)

.css

2

Script (JScript)

.js

3

Data (XML)

.xml

4

Image (PNG)

.png

5

Image (JPG)

.jpg

6

Image (GIF)

.gif

7

Silverlight (XAP)

.xap

8

StyleSheet (XSL)

.xsl, .xslt

9

Image (ICO)

.ico

10

 

How to refer web Resources?

  1. use $webresource directive (in Sitemap or Ribbon)
  2. outside an entity form or chart you must create an HTML Web resource to be the host page for the Silverlight Web resource. Then use the $webresource: directive to open the HTML Web resource
  3. Use Relative URL where the $Webresource directive is not supported.