Wednesday, July 27, 2011

Setting a Lookup value using JavaScript

Below is a sample code for setting the value of a lookup using Javascript in CRM 2011.

It also shows what code change has happened from CRM 4.0
I found this code sample from this blog link


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}]);


No comments:

Post a Comment