CRM 2011 – How to set up a lookup using Javascript

Posted on February 18, 2011

15


I haven’t had to use this javascript yet but I know I am going to need in the future, so I am going to blog about it so I can find it.

there are quite a few examples of this but this blog post compares it to CRM 4 as well, which is extra useful.

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

if you want some more examples and a discussion this forum discussion is the place to look

This page also had an interesting link to an article

Seven JavaScript Things I Wish I Knew Much Earlier In My Career

which I found interesting because I know very little about Javascript

About these ads