Back to Basics # 66: Working with a Html Webresource in Dynamics CRM

Introduction:

During certain scenarios we must build a custom html to show data from Dynamics CRM as per customer requirement. As an example, a separate tab was shown on contact form to show selected contact’s Account Address details in the below

Step 1:

Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the   below figure.

Step 2:

After Step 1, create a Webresource of type html and upload an empty html  as shown  in the below figure.

Step 3:

After Step 2, open html and write the below code

<html>

<head>

http://ClientGlobalContext.js.aspx

<script type=”text/javascript”>

function onLoad() {

    var contactGUID = parent.Xrm.Page.data.entity.getId().replace(“{“,””).replace(“}”,””);;

             Xrm.WebApi.retrieveRecord(“contact”, contactGUID, “?$select=fullname&$expand=account_primary_contact($select=address1_line1)”).then(

            function success(result) {

                console.log(“Retrieved values of Account :  Address: ” + result.account_primary_contact[0].address1_line1);

                                                document.getElementById(“contactpara”).innerHTML = “Retrieved values of Account :  Address: “+result.account_primary_contact[0].address1_line1;

                // perform operations on record retrieval

            },

            function (error) {

                console.log(error.message);

                // handle error conditions

            }

        );

}

</script>

</head>

<body onload=”onLoad()”>

This is a Html Web resource<br>

<p id=”contactpara”></p>

</body>

</html>

 as shown in the below figure.

Step 4:

After Step 3,  go to the contact form and create a tab and section and in that add this Webresource save it and publish it as shown in the below figure

Step 5:

After Step 4, open any contact record and select Custom Html Tab and observe Selected contact related Account Address information displayed in contact record as shown in the below figure.

Note:

  1. Make sure to publish all customizations and upload html file.
  2. Make sure to include ClientGlobalContext.js.aspx script other wise you get an issue with parent.xrm object in code.

Conclusion: In this way, one can easily use html as a Webresource to show contact related information in custom way other than using Forms.

One thought on “Back to Basics # 66: Working with a Html Webresource in Dynamics CRM

  1. Pingback: Back To Basics : Curated List of Articles in a Single Page – Common Man Tips for Power Platform, Dynamics CRM,Azure

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 )

Facebook photo

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

Connecting to %s