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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How to prevent field onchange event from getting fired in a loop.

(0) ShareShare
ReportReport
Posted on by 402

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.

I have the same question (0)
  • Suggested answer
    Ankit Sabharwal Profile Picture
    Microsoft Employee on at

    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.

  • Henry J. Profile Picture
    5,237 on at

    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

  • Suggested answer
    Mohammed Fakhri Profile Picture
    402 on at

    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. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 71 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 54 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans