Change the display text in a lookup in CRM 2011

The following function enables you to change display value of a lookup in MS CRM. In the example below we have a custom entity to register multiple roles/relationships between accounts and contacts. Obviously, one contact can work for multiple accounts at any time or become a member of a society or association.

We have modified the case form so we can search for all relationships linked to the selected account (not just the primary ones) and  fill in the responsible contact. Since multiple roles can exist with the same name we decided to modify the name of the relationship lookup to display both the contact name and name of the role:


You can also use this function if for example in the account lookup you want to see account number instead of the account name.

Copy the function below in the onload event and use the example to call it.

function gLookupChangeDisplayValue(fieldname, displayvalue){
 This function is used change the display value of a lookup
 This function requires the following parameters:
  fieldname :   name of the field
  displayvalue:  text to display in the lookup
 Returns: nothing
 Example:  Example: gLookupChangeDisplayValue('your field', 'text to display')
 Designed by: Geron Profet (
 var lookupData = new Array();
 var lookupItem= new Object();
 var lookup = document.getElementById(fieldname);

 if (lookup != null && lookup.DataValue != null){
  if(displayvalue != ''){ = lookup.DataValue[0].id;
   lookupItem.typename = lookup.DataValue[0].typename; = displayvalue;
   lookupData[0] = lookupItem; 
   lookup.DataValue = lookupData;

TIP: alternatively you can also use gLookupSetValue(), see Related Posts.


About Dynamics CRM Guru

We are a group of CRM Consultants and have significant experience in transforming businesses in the right way. We use this platform to share our knowledge which might help many others in the digital transformation journey. We are happy to help you if you are looking for any assistance in CRM implementation projects.

Posted on August 18, 2011, in Microsoft CRM 2011, Microsoft Dynamics and tagged , . Bookmark the permalink. Leave a comment.

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: