Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Model-Driven app, Clear field when another field changes?

(0) ShareShare
ReportReport
Posted on by 780
I feel like this should be pretty simple but I'm failing to accomplish it. I have a field named Payor and one named Payor Type. When my Payor Type field changes, I want to clear out any value in the Payor field. 
I would love to do this OOB instead of through code but I'm not seeing the option to do so. Please correct me if I'm wrong there.
 
Here's my JS function that I'm trying to use. I'm not great with JS so I'm sure there's something wrong here.
 
function clearPayorField(executionContext) {
    var formContext = executionContext.getFormContext();
    formContext.getAttribute("appdev_payor").setValue(null);
}
 
Categories:
  • Verified answer
    notj Profile Picture
    notj 780 on at
    Model-Driven app, Clear field when another field changes?
    OK, I finally got it. Most of the things I came across said use the logical name, this was incorrect. Using Schema name and updated code below resolved it. Hopefully someone in the future finds this early in their search instead of two days later like me.
     
    function clearPayorField(executionContext) {
        var formContext = executionContext.getFormContext();
        var payorField = formContext.getAttribute("appdev_Payor"); // Replace "appdev_Payor" with the actual Schema name of your field
        
        if (payorField) {
            payorField.setValue(null);
            console.log("Payor field cleared successfully.");
        } else {
            console.error("Error: Payor field is null or undefined. Please check the schema name.");
        }
    }
     
     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,691

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 65,019

Leaderboard