Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Error Handling
Unanswered

Power Apps Model Driven Javascript Set Lookup fails when setting to current saved value

(0) ShareShare
ReportReport
Posted on by

So i got a weird error of "t.name.replace is not a function" when using Javascript formContext.getAttribute().SetValue() on a lookup column. The idea i want to achieve here is that i want to dynamically set a lookup column depending on what Choice Column we pick in the main form. Then use a Display->Form Component to display a couple of related columns according to the lookup column.

 

I put the javascript code on the OnChange trigger of the Choice Column. As for mapping what choice column value will set what value to the lookup table, i have a dedicated table for that. All choices will have a one to one relation with the lookup value/id. The javascript will simply query the necessary data to set the lookup column. And this setup works somewhat, but only when the choice column is set to a new choice/lookup id. If it is changed to the same choice as the one it is saved on the dataverse, it will produce the error. The weird thing is, i checked the values of "lookupValue" and it should be right. Is this a bug from microsoft end?

 

 

function dynamicApproval(executionContext) { //On Change di Approval Path
 var formContext = executionContext.getFormContext();
 var approvalid = formContext.getAttribute("bkp_approvalpath").getValue();
 var Retrievepromise = retrieveApproval(approvalid)
 Retrievepromise.then(
 success => {
 var lookupValue = new Array();
 lookupValue[0] = new Object();
 lookupValue[0].entityType = "bkp_perjalanandinasapproval";
 lookupValue[0].id = success.bkp_perjalanandinasapprovalid;
 lookupValue[0].name = approvalid;
 var approverid = success.bkp_approverid
 try {
 formContext.getAttribute("bkp_approverid").setValue(approverid);
 formContext.getAttribute("bkp_approval").setValue(lookupValue); //THE LINE CAUSING THE CATCH
 }
 catch (err) {
 alert("Error: " + err.message); //THE LINE CAUSING THE ALERT
 }
 },
 failure => {
 alert("Retrieve Approval Failed")
 }
 )
}

async function retrieveApproval(approvalid) { //Retrieve Approval for Dynamic Approval
 try {
 const record = await Xrm.WebApi.retrieveMultipleRecords("bkp_perjalanandinasapproval", "?$select=bkp_perjalanandinasapprovalid,bkp_approverid&$filter=bkp_name eq '" + approvalid + "'");
 return record.entities[0]
 }
 catch (err) {
 alert(err.message);
 }
}

 

 

Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Error Handling

#1
stampcoin Profile Picture

stampcoin 58

#2
DS-11051211-0 Profile Picture

DS-11051211-0 20

#3
HumanOnly Profile Picture

HumanOnly 6

Overall leaderboard

Featured topics