Description
This article will describe the CRM Lookup field in detail and how to get and set its properties using javascript.
The lookup field is an array that contains a collection of name/value pairs.
But what is a name/value pair in javascript? Look no further than the Object class.
Example:
var obj = new Object();
obj["name"] = "value";
//Running alert(obj["name"]) will display "value"
Name Value Collection
Name Value
id Gets or sets the GUID identifier.
name Gets or sets the name of the record to be
displayed in the lookup.
type Gets or sets the object type code
Code
Retrieving values from a Lookup field
Example: with crmForm.all.new_mylookup
var lkup = crmForm.all.new_mylookup;
if(lkup != null)
{
var arr = lkup.DataValue;
if(arr.length > 0)
{
var objNameValues = arr[0];
if(objNameValues != null)
{
alert(objNameValues.id);
alert(objNameValues.name);
alert(objNameValues.type);
}
}
}
Code
Setting values in a Lookup field
Example: with crmForm.all.new_mylookup
var objNameValues = new Object();
objNameValues["id"] = "{GUID}";
objNameValues["name"] = "Name";
// Entity type code
objNameValues["type"] = "TYPE CODE";
crmForm.all.new_mylookup.DataValue =
new Array(objNameValues);

0 comments:
Post a Comment