Hi folks,
I found out an elegant way to set a lookup. Here’s the old way:
var lookup = new Array();
lookup[0] = new Object();
lookup[0].id = 'fc62d5f4-a589-452d-b134-aaa080c0d75a';
lookup[0].entityType = 'contact';
lookup[0].name = 'Nick Plourde';
Xrm.Page.getAttribute('primarycontactid').setValue(lookup);
Here’s the nicer way:
var lookup = [{
id: 'fc62d5f4-a589-452d-b134-aaa080c0d75a',
entityType: 'contact',
name: 'Nick Plourde',
type: 'lookup'
}];
Xrm.Page.getAttribute('primarycontactid').setValue(lookup);
And don’t forget you can still do this:
Xrm.Page.data.entity.getEntityReference();
That’s all!