Showing related information in a CRM 2011 form

February 4, 2011 5 comments

With CRM 2011 on the verge of being released there are new features being introduced that will allow you to show  1:N related records in a Sub Grid but there is still a limitation of showing information that is from a N:1 (lookup) relationship. 

Using some other new features of CRM 2011 I’ve created a Web Resource that will allow you to show related information from a lookup field. 

This Web Resource is a custom html page that pulls information from a specified lookup and queries CRM, using the new REST endpoint,  for the related data and displays it in a simple format.

Here is what it looks like loaded into the form.  This example shows information being pulled for the Primary Contact on the Account form.




The Web Resource pulls the GUID and Record Type from the Primary Contact Field and using the Field parameters specified on the Web Resource, queries for the contact information and displays it inline.


Here is how to set it up. 


1. Download the Solution file ***HERE***

2. Import the Solution File.  After the import you should have a new solution  called “Related Information”


3. Open the Solution to verify you have 3 new Web Resources.


4. Open up the entity form that you want to add the Web Resource to.  Example: Account Form (Tip: You can now open an entity record, click the “customize” tab at the top and then click the “Form” button to open up the designer)

5. Either highlight an existing section or create a new section to add your Web Resource to.

6. Once a section is highlighted, click the “Insert” tab at the top and then click the “Web Resource” button on the ribbon.


7. In the Web Resource field, select the related.html WR that was added.

8. Enter a name into the “Name” and “Label” field.

9. Enter the parameter string in the “Custom Parameter(data)” field.


  • lookup – The lookup column name that you want to show related information from.  Example: primarycontactid
  • fields – Comma delimited string of columns you want to pull from the related entity. Uses Schema Name
  • labels – The labels you want to display for each field.  Has to be in the same order as the field list.

Example: lookup=primarycontactid&fields=FirstName,LastName,Telephone1,EMailAddress1&labels=First Name,Last Name,Business Phone,Email Address


10. Click Ok

11. Save the Form

12. Publish Customizations and test your form




This customization is provided as-is with no warranty.


How to pull entity information from the Microsoft CRM MetaData Service using javascript.

December 15, 2008 6 comments


The following code will pull entity information, using the Metadata service, using javascript.  This code is useful for pulling the objecttypecode dynamically when they may differ between environments.

var _sWebServicesNamespace = "";

function _RemoteMetaCommand(sCommand, sAction)
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");"POST", "/mscrmservices/2006/metadataservice.asmx" , false);
xmlhttp.setRequestHeader("Content-Type","text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", _sWebServicesNamespace + "/" + sAction);

var soapmessage = "<?xml version=’1.0′ encoding=’utf-8′?>"
soapmessage += "<soap:Envelope xmlns:xsi=’’ xmlns:xsd=’’ xmlns:soap=’’>"
soapmessage += "<soap:Body>" + sCommand + "</soap:Body></soap:Envelope>"

return xmlhttp.responseXML;

var entity = "new_country"
var query = "<RetrieveEntityMetadata xmlns=’’>"
query += "<entityName>" + entity + "</entityName><flags>EntityOnly</flags></RetrieveEntityMetadata>"

//Get ObjectTypeCode

var result = _RemoteMetaCommand(query, "RetrieveEntityMetadata").selectSingleNode("//ObjectTypeCode");

var countryentitytypecode = result.text;


Here is the response.

Categories: Uncategorized

Auditing for CRM 4.0

July 7, 2008 5 comments

This is a plugin that I developed to audit transactions in CRM 4.0.  The records that are created are stored in CRM and can be related to the entities in CRM.


  • Audit entities in CRM
  • Show differences with each audit
  • Take advantage of CRM features since the Audit records are CRM entities.
  • Made generic to work with most, if not all, messages in CRM

Messages Tested

  • Create
  • Update
  • Delete
  • Retrieve (Read) – Use caution when using this one.  A read transaction occurs after other messages.
  • Assign
  • SetStateDynamicEntity (Change State)

Download Here

  • Guide
  • Plugin DLL
  • Customization File
  • Source Code

This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized

How to change the entity drop down for the Customer Lookup

December 12, 2007 1 comment

In this post, I’m going to show you how to modify the entity drop down for the Customer Lookup without changing the security for the whole application.  

I’m going to use the customer lookup for opportunity as our example.   By default you have Account and Contact in the drop down for the ‘Look For:’ search criteria.


If you look at the html for the customer lookup field, on the opportunity form, it looks like this.

<img src="/_imgs/btn_off_lookup.gif" id="customerid" class="lu" tabindex="1010" lookuptypes="1,2" lookuptypenames="account:1,contact:2" lookuptypeIcons="/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif" lookupclass="BasicCustomer" lookupbrowse="0" lookupstyle="single" defaulttype="0" req="2">

The 3 attributes we will need to change is lookuptypes,lookuptypeNames and lookuptypeIcons.

Reorder the Dropdown

To reorder the drop down, add the following code to the ‘OnLoad’ of the Opportunity form.

crmForm.all.customerid.lookuptypes = "2,1"
crmForm.all.customerid.lookuptypenames = "contact:2,account:1"
crmForm.all.customerid.lookuptypeIcons = "/_imgs/ico_16_2.gif:/_imgs/ico_16_1.gif"

The dropdown should default to Contact when it’s opened.


Remove an Entity from Dropdown

To remove Contact from the customer lookup for Opportunity add the following code on the ‘OnLoad’ of opportunity.

crmForm.all.customerid.lookuptypes = "1"
crmForm.all.customerid.lookuptypenames = "account:1"
crmForm.all.customerid.lookuptypeIcons = "/_imgs/ico_16_1.gif"

The lookup should only be for accounts.


Although it may be possible, I wouldn’t add entities to the lookups since the customer relationship does not exist.


This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized

Viewing a Logo in Microsoft CRM

March 29, 2007 3 comments

I’m always getting the question on how to view a logo or image in Microsoft CRM.  Well here is a quick customization you can add to your account form and view a logo.   Once you add this script on the ‘OnLoad‘ event of the form, all you need to do is add an image called ‘logo.jpg’ as an attachment and everything will show up properly.   This customization will even work offline.


var Loaded = false;

if(crmForm.FormType ==2 || crmForm.FormType ==3 || crmForm.FormType ==4)
    // get the notescontrol object
    var oNotes = document.getElementById("notescontrol");

    // attach an event so we know when the notecontrol is done loading
   oNotes.attachEvent(‘onreadystatechange’, LoadLogo);

   // refresh the notecontrol

function LoadLogo()
   if (oNotes.readyState != ‘complete’)

   var oDoc = (oNotes.contentWindow || oNotes.contentDocument);
   if (oDoc.document) oDoc = oDoc.document;
   // attachment use SPAN tags
   var attachments = oDoc.body.getElementsByTagName("SPAN");

   //Iterate through all the attachments.
   for (var i = 0; i < attachments.length; i++)
       // let’s be certain we have an attachment here
       if (attachments[i].attachmentId)
            // is this an image attachment
            if (attachments[i].innerHTML.match(/.*logo\.jpg$/i) && !Loaded)
                  //Get a reference to the table
                 var tr =;
                 var td = tr.insertCell();
                 td.innerHTML = "<img src=’" + attachments[i].url.concat("?AttachmentType=", attachments[i].attachmentType,                                    "&AttachmentId=", attachments[i].attachmentId) + "’/>"
                  Loaded = true;

When your done, your form should look like this.

If you really want to get creative you can go a little further and build a viewer to page through all images that are attached to the record.




This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized

Replicating CRM Records to another CRM System

March 29, 2007 1 comment

A friend of mine called me up and asked if it was possible to create records in one CRM system when they are created in another one.  Well here is a quick example of how to do it.   


  • Both CRM Systems have the exact same fields for the records you will copying.
  • All records in the two CRM systems have the same guids for matching records.

If there are discrepencies with the guids in each system, there will be issues with this example.   When the postImageEntityXml is Deserialized into a DynamicEntity, it has the guid of the source system. When it’s created in the target system, it’s created with the same guid. 

For this example I will show you a simple Post Callout to replicate a Create action, but I recommend sending these transactions to a Message Queue and then processing them from there.   It’s also not only limited to Create, the same thing can be done for other actions.


public override void PostCreate(CalloutUserContext userContext, CalloutEntityContext entityContext, string postImageEntityXml)
    //Create the Service and connect to remote server.
   CrmService service = new CrmService();
   service.Url = "http://<CRMSERVER>/mscrmservices/2006/crmservice.asmx"

   //build the credentials for access if the current user doesn’t have access.
   service.Credentials = new System.Net.NetworkCredential("username","password","domain");

    DynamicEntity entity = (DynamicEntity)Serialization.DeserializeBusinessEntity(postImageEntityXml);

    TargetCreateDynamic targetCreate = new TargetCreateDynamic();
    targetCreate.Entity = entity;

    CreateRequest request = new CreateRequest();

    request.Target = targetCreate;

    CRMSDK.CreateResponse response = (CRMSDK.CreateResponse) service.Execute(request);
private Object DeserializeBusinessEntity( string xml)
    XmlTextReader readerText = new XmlTextReader(new StringReader(xml));
    // De-serialize XML stream using .NET XmlSerializer class
    XmlRootAttribute root = new XmlRootAttribute("BusinessEntity");
    root.Namespace = ""
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(BusinessEntity), root);
    BusinessEntity entity = (BusinessEntity)xmlSerializer.Deserialize(readerText);

    return entity;
    catch (Exception) { throw; }

This code isn’t entity specific so it will work for most of the entities in CRM. All the entity information is in the postImageEntityXml and is Deserialized into the DynamicEntity.

Callout Registration

<callout entity="account" event="PostCreate">
      <subscription assembly="Callout.dll" class="Callout.Migrate">

<callout entity="contact" event="PostCreate">
      <subscription assembly="Callout.Migration.dll" class="Callout.Migrate">

There are a lot more things you can do to improve this process.   This is just a simple example.  Some other things to consider adding into your solution is Message Queueing and Exception Handling.

Hope this helps.

A big shout out to Henry who is out in Ohio this week :).


This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized

Shortcut Buttons in Microsoft CRM

March 28, 2007 Leave a comment

If you want to try to cut down on clicks on CRM forms, one thing you can do is create a ISV button for actions they perform a lot.  For example if users create  appointments from the contact form, they would have to either go to Actions > Add Activity >Appointment in the top menu  or click on Activities > New Activity > Appointment from the menu on the left. 

Here is the shortcut.

Add a ISV button in the isv.config.xml file.

<Entity name="contact">
<ToolBar ValidForCreate="0" ValidForUpdate="1">
<Button Title="New Appointment" ToolTip="Create a new appointment." Icon="/_imgs/ico_16_4201.gif" JavaScript="locAddActTo(4201);" Client="Web" />

The text in Red is the same function called when you click new appointment from the menu. Save the changes  and refresh your contact form. 

Hope this helps


This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized

Custom Lookups in Microsoft CRM

March 28, 2007 1 comment

If you’re like me and don’t like having to do your own custom lookups as an ISV button, then here is a better way of doing it.  This customization will allow you to implement lookup functionality and have it look like the CRM lookups.  It just looks a lot cleaner.

Adding the Button

First you will need to determine which field you want to add the button to and get the id of the input.  For this example I’ll use the country text field on the Contact form which is address1_country. Then add the following code to the ‘OnLoad’ of the Contact Form.

var beforehtml = "<TABLE class=’lu’ style=’TABLE-LAYOUT: fixed’ cellSpacing=’0′ cellPadding=’0′ width=’100%’><TR><TD>"
var afterhtml = "</td><td width=’25’ align=’right’><img src=’/_imgs/btn_off_lookup.gif’ id=’customlookup’ style=’cursor:hand;’ onclick=’CustomLookup();’/></td></TR></TABLE>"

document.getElementById("address1_country").parentElement.innerHTML = beforehtml + document.getElementById("address1_country").parentElement.innerHTML + afterhtml;

The form should look like this after you publish your changes and open the form. 

Notice the button next to the Country/Region field. This is just a text box but it has a button like a lookup. 

Opening the Lookup

Once you have the button in place you will need to add the onclick function to the ‘OnLoad’ of the Form. Add the following script to the form.  You can develop the custom lookup to do anything you like, you could even pass parameters to the lookup and do whatever you want.  I usually try to make my custom lookups have the same look and feel as crm.

this.CustomLookup = _CustomLookup;
function _CustomLookup()
var returnval = window.showModalDialog("/Custom/countrylookup.aspx","","dialogWidth:600px;dialogHeight:488px;
if(returnval != "" && returnval != "undefined" && returnval != null)
document.getElementById("address1_country").value = returnval;

Once the user has selected a value from you lookup, set the returnvalue of the window and then it will be assigned to your returnval variable.  Then make sure it actually has a value, and then populate the text box.

You’re good to go. Hope this helps.


This customization may not be supported by Microsoft and is provided as-is with no warranty.

Categories: Uncategorized