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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Business Rule for Fiel...
Power Apps
Unanswered

Business Rule for Field Lock Unlock not working correctly when OnChange Event of Field has javascript attached

(0) ShareShare
ReportReport
Posted on by 305

I have a business  rule which says if Owner Contains Data then unlock Payer, else Lock Payer.

Also, Payer has set been to read only on the form. 

Payer Events has Javascript attached to it's OnChange. This script then sets a filter on another dropdown but does nothing to Payer.

 

 

Once Owner is selected and then deselected, Payer does become locked.

But at form load, Payer becomes unlocked inspite of Owner being empty

 

If the on change javascript is removed though, everything works as expected that is Payer is locked on form load

I have the same question (0)
  • AhmedSalih Profile Picture
    6,678 Moderator on at

    Hello, @Rutu01, I had similar issue few months back. I found the workaround is to not use the modern controls. I haven't revisited this app recently to dig deeper into the issue or report it which I would probably do if you confirmed my doubts 🙂

     

     

  • Verified answer
    Shawn11 Profile Picture
    152 on at

    Hello @Rutu01,

    Please refer https://neilparkhurst.com/2021/10/19/javascript-and-business-rules/ 

    In this blog they have mentioned to use fireonchange()

    <<FormContext>>.getAttribute(“myattribute”).fireOnChange();

     

    Hope this helps

  • Rutu01 Profile Picture
    305 on at

    This issue seemed to be happening because in my form on load i was setting the owner to null ( in case of new records) with javascript. But before this executed, the owner field was (behind the scenes, i couldn't see this visually) being populated with default value that is the current user. This was causing the Payer dropdown to be unlocked. Adding fireOnChange() to my javascript fixed this. 

     

    Another solution that worked was modifying the business rule to state that If Owner contains data AND the owner name contains "-" , but this only worked in my case because the user names in my situation don't contain "-", only the team names do. The fireOnChange() as suggested by @ShawnDante feels like the more  reliable and correct way to solve it. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard