Hi guys, I'm having some difficulty trying to get and set a lookup value. I've created a button on a Case form which opens up a new Email and I want to set the Regarding of that email to the case it just came from.
I don't know if there's a more clever way to do this - currently, this is what I have:
var formContext = executionContext.getFormContext(); //get formContext
function getLookupValue(executionContext) {
var lookupObject = formContext.getAttribute(incidentid).getValue(); //get the Lookup Object
if (lookupObject != null) {
var lookupObjectValues = lookupObject.getValue();//get the Lookup Value
if (lookupObjectValues != null) {
var RecordId = lookupObjectValues[0].id; //get the Lookup id
var RecordName = lookupObjectValues[0].name; //get the Lookup Name
var EntitySchemaName = lookupObjectValues[0].entityType; //get the Lookup EntityName
}
}
}
function setLookupValue(executionContext, regardingid, RecordId, RecordName, EntitySchemaName) {
if(regardingid != null) {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = RecordId;
lookupValue[0].name = RecordName;
lookupValue[0].entityType = EntitySchemaName;
formContext.getAttribute(regardingid).setValue(lookupValue);//set lookupValue from array
}
}
When the button is pressed and the event handler runs, I get a script error:
TypeError: Cannot read property 'getAttribute' of undefined
I feel like I must be missing something fundamental - I've gone through a few iterations with this (I was using the old Xrm.Page before - whoops!) but any advice would be very much appreciated!