This function is intended to be included in the onLoad library of a page or a common .js library. Its purpose is to construct the required object/array for setting a lookup value on a form.
An example of The calling function is also shown (using a value retrieved from a xml doc retrieved from another lookup function)
//--------------------------------------------------------------------------------------------------
function getLookupObject( idValue, lookupLabel, typeName ) {
//Create an array to set as the DataValue for the lookup control.
//then Create an Object add to the array.
//Set the attibutes of teh object
//--------------------------------------------------------------------------------------------------
var lookupData = new Array();
var lookupItem= new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = idValue;
lookupItem.typename = typeName;
lookupItem.name = lookupLabel;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
return lookupData;
};
Example Usage (to set the lookup field new_departmentid):
if ( resultXml.selectSingleNode("//new_departmentid") != null ) {
f.new_departmentid.DataValue = getLookupObject( resultXml.selectSingleNode("//new_departmentid").text,
resultXml.selectSingleNode("//new_departmentid/@name").text,
'new_department' ) ;
}
No comments:
Post a Comment