CRM Javascript – Get and set a lookup field

MicrosoftDynamicsCRM logoIn Microsoft Dynamics CRM it’s possible to link records together using relashionships. You can see an example of lookup field creating a 1:N relashionship between two entities. In the forms you are able to put a grid (of the related records) on the first entity and a lookup field (a reference to the first entity) in the second entity.

Lookup field allow you to insert a sort of “link” to a related record, allowing you to use also a wild card research.

This image shows how a lookup field looks like in the entity form before you choose a related record to insert:

CRM lookup field

 

 

It’s possible to use javascript to do custom action on this kind of field.

The following code shows you how to get and set lookup fields.

Get a lookup value

var lookup = new Array();

lookup = Xrm.Page.getAttribute(“attribute”).getValue();

if (lookup != null) {

var name = lookup[0].name;

var id = lookup[0].id;

var entityType = lookup[0].entityType;

}

Set a lookup value

Xrm.Page.getAttribute(“attribute”).setValue([{ id: recorid, name: recordname, entityType: entityname}]);

No related content found.

Pubblicato da Gianluca Giannone

Titolo di studio: Laurea Magistrale in Informatica. Descrizione: Sono un appassionato del mondo informatico ed in particolare dei software open source. Nonostante possa sembrare in contrasto con la mia formazione scientifica, anche l'arte mi ha sempre affascinato. Da sempre uso linux ed in particolare Ubuntu e Linux Mint.