SetLookupValue
function CleanGuid(id)
{
var guid = id.replace("{", "");
guid = guid.replace("}", "");
return guid.toLowerCase();
}
function SetLookupValue(field, logicalName, id, name)
{
var attribute = Xrm.Page.getAttribute(field);
if(attribute === undefined || attribute == null)
{
return;
}
var value = attribute.getValue();
if(value != null && CleanGuid(value[0].id) == CleanGuid(id))
{
return;
}
attribute.setValue([{
id: id,
name: name,
entityType: logicalName
}]);
attribute.setSubmitMode("always");
}