Using HTML Web Resource in CRM 2011

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">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                Organization Name:-</td>
            <td class="style3" id="td2">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style2">
                User Id:-</td>
            <td class="style3" id="td3">
                &nbsp;</td>
            <td>
                &nbsp;</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.

 


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

6 thoughts on “Using HTML Web Resource in CRM 2011”

Share your thoughts

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