web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : 7Pi9dWxGineStueGWlwIsH
Power Apps - Error Handling
Unanswered

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

Like (0) ShareShare
ReportReport
Posted on 28 Feb 2024 06:47:17 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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Featured topics

Loading complete