Javascript – Set Lookup Details

In previous posts I describe some common functions I use to get field text values, set optionset values from text, set text field values etc. Here is another post containing a standard functions to set lookup values;

// *** FUNCTION: SetLookUp
// *** PARAMS:
// ***    fieldName = The name of the lookup field  
// ***    fieldType = The type of field (contact, account etc)
// ***    fieldId = The ID of the value to set (GUID)
// ***    value = the value(name) to set
function SetLookUp(fieldName, fieldType, fieldId, value) {
	try {
		var object = new Array();
		object[0] = new Object();
		object[0].id = fieldId;
		object[0].name = value;
		object[0].entityType = fieldType;
		Xrm.Page.getAttribute(fieldName).setValue(object);
	}
	catch (e) {
		alert("Error in SetLookUp: fieldName = " + fieldName + " fieldType = " + fieldType + " fieldId = " + fieldId + " value = " + value + " error = " + e);
	}
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s