Tag Archives: MS CRM 2011

Step by Step creating Quick Entity View in MS CRM 2011

During one of our projects we got a requirement to show related entity fields, based on the lookup selection, just like the Quick Entity View feature that we have in Microsoft CRM 2013, so I thought of replicating that for Microsoft CRM 2011. In this article I am sharing code and how to do that so that it can help someone with similar requirements.

Let’s say we want to show contact fields in an account entity form based on the primary lookup selection. To implement this requirement we can use a HTML web resource and use the rest of the endpoints to get contact data based on the contact id selected. So mainly we have the following three steps:

  • Create HTML web resource to get data from child entity and create a html table on the fly.
  • Add HTML web resource in the parent entity form.
  • Create an onchange handler to refresh a HTML web resource when the lookup value is changed.

So let’s create a HTML web resource and name it “/ContactQuickView.html” as in the following.


Click on Text Editor and paste below code:-

<html lang=”en-us”><head>
<title>Contact Quick View</title>
<style type=”text/css”>
font-family: segoe ui;
background-color: #F6F8FA;
td  { width: 130px;
background-color: #F6F8FA;
font-size: 13px;
<script src=”../ClientGlobalContext.js.aspx”></script>
<script type=”text/javascript”>
//check if document is loaded or not
document.onreadystatechange = function () {
if (document.readyState == “complete”) {
parseEntityID();    }  }
function parseEntityID() {
var queryParam = GetGlobalContext().getQueryStringParameters().data;
var fields = queryParam.split(“,”);
var TabName=fields[1];
var SectionName=fields[2];
if ((window.parent.Xrm.Page.data.entity.attributes.get(fields[0])!= null) && (window.parent.Xrm.Page.data.entity.attributes.get(fields[0]).getValue()!=null))  {
var ContactID = window.parent.Xrm.Page.data.entity.attributes.get(fields[0]).getValue()[0].id;
//change tab and section name here
RetrieveContactRecord(ContactID);    }
{   window.parent.Xrm.Page.ui.tabs.get(TabName).sections.get(SectionName).setVisible(false);   }  }
//Read contact information
function RetrieveContactRecord(id) {
var ServerURL=window.parent.Xrm.Page.context.getClientUrl();
var ServiceURL=ServerURL+”/xrmservices/2011/organizationdata.svc”;
var req = new XMLHttpRequest();
req.open(“GET”, ServiceURL + “/Contact” + “Set(guid'” + id + “‘)”, true);
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
if (this.status == 200) {   successCallback(JSON.parse(this.responseText).d);                }
else {  alert(‘Error while reading contact information’);  }  }
req.send();     }
//Added for cross browser support.
function setText(element, text) {
if (typeof element.innerText != “undefined”) {
element.innerText = text;
else {  element.textContent = text;    }  }
//Generate html table to show records
function successCallback(ResultSet)
//store lables
var lbs=new Array();
lbs[0]=”Business Phone”;
lbs[3]=”ZIP/Postal Code”;

//store values
var vals=new Array();
vals[0]=(ResultSet.Telephone1!=null)?ResultSet.Telephone1:” “;
vals[1]=(ResultSet.EMailAddress1!=null)?ResultSet.EMailAddress1:” “;
vals[2]=(ResultSet.Address1_City!=null)?ResultSet.Address1_City:” “;
vals[3]=(ResultSet.Address1_PostalCode!=null)?ResultSet.Address1_PostalCode:” “;
vals[4]=(ResultSet.Address1_StateOrProvince!=null)?ResultSet.Address1_StateOrProvince:” “;
vals[5]=(ResultSet.Address1_Country!=null)?ResultSet.Address1_Country:” “;

//Create a table and header using the DOM
var oTable = document.createElement(“table”);
var oTBody = document.createElement(“tbody”);

for(var i=0; i<6; i++)
var oTRow = document.createElement(“tr”);
var oTRowBlank = document.createElement(“td”);
var oTRowTDBlank1= document.createElement(“td”);
var oTRowTDBlank2= document.createElement(“td”);
var oTRowTD1 = document.createElement(“td”);
setText(oTRowTD1, lbs[i]);
var oTRowTD2 = document.createElement(“td”);
setText(oTRowTD2, vals[j]);

var oTRowTD3 = document.createElement(“td”);
setText(oTRowTD3, lbs[i+1]);
var oTRowTD4 = document.createElement(“td”);
setText(oTRowTD4, vals[j+1]);
document.body.appendChild(oTable);   }
<meta charset=”utf-8″></head><body>

Note: Please make sure to change quotations sign if you are copying code.

Now we have html web resource ready, place it under the parent entity form, while placing web resource we need to pass three parameters:

  • Name of the lookup field for child entity.
  • Name of the tab and section where we have placed web resource like below


Now we need to create a JS webresource and need to use below code. We have to call this function on primary contact  lookup field onchange on account entity form to refresh web resource once value will be changed.
function reloadTerrtoryQuickView()

{ var wrControl = Xrm.Page.ui.controls.get(“WebResource_TerritoryQuickView”);

wrControl.setSrc(wrControl.getSrc()); }

And once we will open account form it will show related information based on the primary contact selected like below

contactviewImageEnjoy !!!


Leave a comment

Filed under MS CRM 2011, Step By Step MS CRM 2011

Accessing custom aspx page from MS CRM 2011 and passing EntityID

Recently we got one request to show custom website page in CRM from left navigation in MS CRM 2011 based on the entity id. I am going to share the process so that it can help someone.

In our scenario we need to:

  • Create left navigation link for custom web page hosted on intranet website.
  • Pass current entity id to custom web page.
  • Custom page should be visible in associated view iframe.

As we need to pass entity id to custom web page, so we can create html web resource which will read entity id and will pass it to custom web page. Follow below steps to create html page:

  • Open default solution or you can create separate solution.
  • Navigate to Web Resources and select New to create new html web resource
  • Provide basic details for html web resource.
  • Open html editor and use below code



<script language=”javascript”>

function SetLeftNavigation() {

var WebPageURL=”http://CustomPageURL_Change&#8221;; //change custom page url

var EntityId = window.parent.Xrm.Page.data.entity.getId();//to access entityid from entity form

EntityId = EntityId.replace(‘{‘, ”).replace(‘}’, ”);

var iFramUrl = WebPageURL +”?id=”+ EntityId;

location.href = iFramUrl;





<script language=”javascript”>





  • Save and publish your web resource.
  • Open your entity form, where we want to add left navigation.
  • Double click on left navigation section where you want to add custom link.
  • Navigate to Insert->Navigation Link to add new link.
  • Enter details like below


Name: Label that you want to give to custom link

Icon: you can create a custom image web resource and use it for icon

Web Resource: Select the html web resource we just created.

  • Save and publish your changes and test it.

Note: Please make sure to change quotation if you are copying code.

1 Comment

Filed under MS CRM 2011

Microsoft Dynamics CRM 2011 Application Design

It is my pleasure to share this news with my readers that I have been working on a book for last few months and now it is available on Packtpub.com.


Microsoft Dynamics CRM 2011 Application Design is the solution to your business needs. Whether you are just starting out or are an old hand this book will provide you with the results you need. Guiding you through real world applications that will benefit your business instantly.

Throughout this book you will be building your knowledge through hands on application development from a simple employee recruitment application through to managing an entire hotel. Microsoft Dynamics CRM 2011 Application Design” gives you the tools you need to successfully build fully customized applications for all of your business needs.

If you want to fully utilize the xRM abilities of CRM 2011 to create applications for any situation then this is the book that will help you do it.



Filed under MS CRM 2011, MS CRM Book

New Features in “Polaris”

Check new features in Q4 release : http://blogs.msdn.com/b/ukcrm/archive/2012/11/16/crm-online-polaris-release-q4-2012-details.aspx

Leave a comment

Filed under MS CRM 2011

Step By Step Adding Configuration Page in Solution MS CRM 2011 Part -2

In my earlier post I have used a simple html web resource to set as configuration page and I found this post quite popular, so I thought to write another post on this. In this post I will show how can we get configuration details from xml web resource to display it in configuration page. We can use it in different way, but for the demo purpose I have kept it simple. You can follow below steps to show configuration data stored in xml web resource:

1. Create a xml web resource where we can store our configuration information, for example our product registration information. I am using below xml in my  new_Configuration.xml web resource

<?xml version=”1.0″ encoding=”utf-8″?>
  <RegisteredTo>Mahender Pal</RegisteredTo>
  <Description>This is a xRM Demo solution</Description>

2. Create a new html web resource and add below code to read data from our xml web resource

<HTML xmlns=”http://www.w3.org/1999/xhtml”><HEAD><TITLE>xRM Demo</TITLE>
<SCRIPT type=text/javascript>
function ShowConfiguration() {
var Webresourceurl = WebResourceURL; //we need to provide our xml webresource url here we can get it from CRM
var nodePath = “//Configuration”;
var XmlDoc= new ActiveXObject(“Microsoft.XMLDOM”);
XmlDoc.preserveWhiteSpace = true;
XmlDoc.async = false;
var nodelist;
nodelist = doc.selectNodes(nodePath);
document.getElementById(‘registeredto’).value = nodelist[0].selectSingleNode(“RegisteredTo”).nodeTypedValue;
document.getElementById(‘registerationid’).value = nodelist[0].selectSingleNode(“RegisterationID”).nodeTypedValue;
document.getElementById(‘description’).value =  nodelist[0].selectSingleNode(“Description”).nodeTypedValue;

<META charset=utf-8></HEAD>
<BODY onload=ShowConfiguration() contentEditable=true bgColor=#6666ff>
<P><FONT size=6 face=”Tahoma, Verdana, Arial”><FONT color=#ffffff><STRONG>Product Registertion Information</STRONG></FONT>&nbsp;</FONT></P>

<TD><STRONG><FONT color=#ffffff>Product Registered To :</FONT></STRONG></TD>
<TD><INPUT style=”BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BACKGROUND-COLOR: #6666ff; COLOR: #ffffff; FONT-SIZE: 12px; BORDER-TOP: medium none; FONT-WEIGHT: bold; BORDER-RIGHT: medium none” id=registeredto TD <></TD>
<TD><STRONG><FONT color=#ffffff>Registration ID :</FONT></STRONG></TD>
<TD><INPUT style=”BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BACKGROUND-COLOR: #6666ff; COLOR: #ffffff; FONT-SIZE: 12px; BORDER-TOP: medium none; FONT-WEIGHT: bold; BORDER-RIGHT: medium none” id=registerationid TD <></TD>
<TD><STRONG><FONT color=#ffffff>Product Description :</FONT></STRONG></TD>
<TD><INPUT style=”BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BACKGROUND-COLOR: #6666ff; COLOR: #ffffff; FONT-SIZE: 12px; BORDER-TOP: medium none; FONT-WEIGHT: bold; BORDER-RIGHT: medium none” id=description size=40 TD <></TD></TR></TBODY></TABLE></BODY></HTML>

3. Set your html web resource in configuration page lookup in solution and save it.

Now when you will try to click configuration page you should get it like below


Filed under MS CRM 2011

Working with MS CRM 2011 data types

I have seen many question in MS CRM Development where developers asking for MS CRM 2011 data type related question, like how to set lookup field, how to set/retrieve optionset value. so I thought to write code to show how we can set different data type field in MS CRM 2011.

Below is the example to create account using late bound

Entity _Account = new Entity();
_Account.LogicalName = “account”;
//setting text field
_Account.Attributes.Add(“name”, “Myaccount123”);

//setting optionset field
_Account.Attributes.Add(“accountcategorycode”, new OptionSetValue(2));

//setting datetime field
_Account.Attributes.Add(“new_collectiondate”, new DateTime(2012, 3, 25));

//setting currency field
_Account.Attributes.Add(“creditlimit”, new Money(300));

//setting lookup
_Account.Attributes.Add(“parentaccountid”, new EntityReference(“account”, new Guid(“XXX-XXX……..”)));

//setting decimal
_Account.Attributes.Add(“new_executivecommission”, new Decimal(55.5));

//setting boolean
_Account.Attributes.Add(“new_isbilled”, true);


we should get new account created like below

In next post I will show how to retrieve different data types fields using server side code.

Enjoy !!!


Filed under MS CRM 2011