Home > CRM 2011, JScript > Passing multiple values to web resource(HTML/Silverlight) in CRM 2011

Passing multiple values to web resource(HTML/Silverlight) in CRM 2011

Lets assume a requirement as below

  • I need to show a custom HTML page on my “Account” form
  • Read few “Account” entity field values (i.e.,  Address1_line1,City etc…) from my HTML page
  • Account fields to pass to HTML need to be configurable (i.e., Fields I need to read in my HTML may change)


In CRM 2011, we can

  • Add a HTML file as web resource and add it to entity form
  • We can pass a single custom parameter called data
Custom Parameter (data)

Custom Parameter (data)

  • Since only one value can be passed within the data , we can pass a multi-line string separated by special character


  • Create a blank HTML file using visual studio  and add this as web resource to CRM
  • Open the “Account” customization form and add the HTML web resource added in above step
Add web resource to Account entity

Add web resource to Account entity

  • After you chosen the HTML as web resource, you get a “Web Resource Properties” section and looks as below
Web Resource Properties

Web Resource Properties

  • In the “Web Resource Properties” section, below is the description of each field
    • Custom Parameter(data)         – The values you want to pass to your web resource.
      • Since I want Address1_line1,City fields of account, I provided those 2 fields separated by  ,(comma)
      • We can read the value passed as query string
      • Sample query string looks as ?data=%22emailaddress1%22%2c%22address1_city%22
    • Restrict cross-frame scripting –  Uncheck this to read content from CRM form
    • Pass record object-type code and unique identifier as parameters – By choosing this, we can read entity information(i.e., Record Id, orglcid, orgname,objecttypecode etc..) as query string parameters
      • The sample query string looks as id=%7b44623C6A-4452-E211-8FB3-00155DC87C64%7d&orglcid=1033&orgname=ABCD&type=1&typename=account&userlcid=1033
  • Now open the “HTML” web resource and copy and paste the below content

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”&gt;

<html xmlns=””&gt;



    <script type=”text/javascript”>

        document.onreadystatechange = function () {

            // If page load completes call the “getDataParam()” to read parameters

            if (document.readyState == “complete”) {




        function getDataParam() {

            var vals = new Array();

            // The parameters we pass comes as query string

            // Read it using “”

            if ( != “”) {

                vals =“&”);

                for (var i in vals) {

                    vals[i] = vals[i].replace(/\+/g, ” “).split(“=”);


                // Look for the parameter named ‘data’ among query string parameters

                for (var i in vals) {

                    if (vals[i][0].toLowerCase() == “data”) {

                        // Call parseDataValue to read params passed in “Custom Parameter(data)”







        function parseDataValue(datavalue) {

            if (datavalue != “”) {

                var vals = new Array();

                vals = decodeURIComponent(datavalue).split(“&”);

                // You get “emailaddress1″,”address1_city” as a string in vals[0]

                // Split with , (comma) to read the schema name

                var email_schmaname = vals[0].split(‘,’)[0];

                var city_schmaname = vals[0].split(‘,’)[1];

                // Get the values of account’s email & city using the schema names we passed in (data)

                var emailAddress =;

                var city =;

                alert(“Account’s email – ” + emailAddress);

                alert(“Account’s city – ” + city);







The HTML file script has 2 functions

  • getDataParam: Called from the body.onload event, this function retrieves any query string parameters passed to the page and locates one named data.
  • parseDataValue: Receives the “data” parameter from getDataParam function.

Points to ponder

  • We can’t access ‘Xrm’ object directly, use window.parent.Xrm
  • document.readyState == “complete” will become true if the page load complets
  • Refer the inline comments of HTML file to understand the jscript


  1. August 5, 2014 at 7:13 PM

    Can’t get the values into the querystring of the webresource iframe url. I add the field name (schema name) to the custom parameter (data) and get the field name on the querystring (static) and not the field value. I posted que question on stackoverflow as well here:

  2. August 5, 2014 at 8:55 PM

    whats the point of reading a querystring to get a schema name? Can’t you just hardcode the schema name on “;” since the schema name doesn’t change?

  1. No trackbacks yet.

Leave a Reply

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

You are commenting using your 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: