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:

image

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 (www.crmxpg.nl)
 */
 var lookupData = new Array();
 var lookupItem= new Object();
 var lookup = document.getElementById(fieldname);

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

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

Advertisements

About Dynamics CRM Guru

We are a group of CRM Consultants and have rich experience in all Microsoft CRM versions. Currently we provide training in Microsoft CRM 2015/CRM 2013 and CRM 2011.

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:

WordPress.com Logo

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