Monday, September 28, 2009

Lookup: Retrieve Column values from Lookup window in MS CRM 4.0

if(Xrm.Page.getAttribute("<lookupId>") != null)
{
var entityId = document.getElementById( "<lookupId>");
var lookupItems = entityId.items[0].values;

alert(lookupItems[0].value); // First column value of Lookup
alert(lookupItems[1].value); // Second column value of Lookup
alert(lookupItems[2].value); // Third column value of Lookup
alert(lookupItems[3].value); // Fourth column value of Lookup
alert(lookupItems[4].value); // Fifht column value of Lookup
alert(lookupItems[5].value); // Sixth column value of Lookup
}

Note: You should disable the Automatic Resolution, so that users cannot add values automatically. This script will work only if the Lookup View is loaded.

No comments: