Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Set Lookup Value using JavaScript Tip

Rhett Clinton Profile Picture Rhett Clinton Moderator

Everyone has seen the method of updating a CRM lookup field on a form, most examples look something like this.

// CRM 4
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].typename = typeValue;

crmForm.all.fieldName.DataValue = value;

// CRM 2011
var value = new Array();
value[0] = new Object();
value[0].id = idValue;
value[0].name = textValue;
value[0].entityType = typeValue;

Xrm.Page.getAttribute("fieldName").setValue(value);

How about doing it on one line like this instead.


// CRM 4
crmForm.all.field.DataValue = [{id: idValue, name: textValue, typename: typeValue}];

// CRM 2011
Xrm.Page.getAttribute("fieldName").setValue( [{id: idValue, name: textValue, entityType: typeValue}]);

There is a short but interesting article about JavaScript called Seven JavaScript Things I Wish I Knew Much Earlier In My Career by Christian Heilmann if you have some spare time to read.


Filed under: MS CRM Tagged: Javascript, Lookup, MSCRM

This was originally posted here.

Comments

*This post is locked for comments