Sorry, I'm new to all Power Apps world. I call this function onLoad when a user clicks reply in timeline of a case.
This is my incomplete code. I can't access parentactivity id on the e-mail form. it's not there?
I think one of the mistakes lies in the line:
var lookupObject = formContext.getAttribute("ticketnumber"); // Get the Lookup Object
var formContext;
function getLookupValue(executionContext) {
formContext = executionContext.getFormContext(); // Get formContext
var lookupObject = formContext.getAttribute("ticketnumber"); // Get the Lookup Object
if (lookupObject != null) {
console.log("lookupObject value is not 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
// Call setLookupValue with the retrieved values
setLookupValue(executionContext, "regardingobjectid", RecordId, RecordName, EntitySchemaName);
}
} else {
console.log("lookupObject value is null")
}
}
function setLookupValue(executionContext, regardingAttribute, RecordId, RecordName, EntitySchemaName) {
if (regardingAttribute != null) {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = RecordId;
lookupValue[0].name = RecordName;
lookupValue[0].entityType = EntitySchemaName;
formContext.getAttribute(regardingAttribute).setValue(lookupValue); // Set lookupValue from array
console.log("Lookup value set for " + regardingAttribute);
} else {
console.log("Lookup value not set");
}
}
// OnLoad function to initiate the process
function onLoad(executionContext) {
console.log("onLoad function called.");
getLookupValue(executionContext);
}