Announcements
I am updating optionset value inside onchange function to the previous selection after showing an alert. which works fine but the function is again trigered due to this update. How can I prevent this.
Below id my code:
//registered on change of new_decision field
function onchange(){
var formContext = eContext.getFormContext();
alert("This is not a valid decision for application");
formContext.getAttribute("new_decision").setValue();
}
I have tried few things like atttaching onchange through addonchange method insted of Form UI.
I have also turned on legacy form rendering but it is firing in a loop.
Thanks Ankit and Henry.
Ankit, I liked your solution (havent tried though) but I used SetTimeOut function to my rescue. -
Use this to set value - window.setTimeout(function () { formContext.getAttribute("new_decision").setValue(); }, 300); |
This wont trigger the OnChange again in a loop.
Hi Mohammed,
Please refer to this article on Attribute OnChange Event as well:
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/attribute-onchange
Henry
Hello Partner,
If this is one time execution, like after alert you set the right value and you don't want to fire the OnChange event, you can fiddle with the code as follows :-
var checkFlag = true;
function onchange(){
if(checkFlag)
{
var formContext = eContext.getFormContext();
alert("This is not a valid decision for application");
formContext.getAttribute("new_decision").setValue();
checkFlag= false;
}
}
Hope this helps.
Best regards,
Ankit
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
André Arnaud de Cal...
294,099
Super User 2025 Season 1
Martin Dráb
232,866
Most Valuable Professional
nmaenpaa
101,158
Moderator