Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Different methods of OnChange

(0) ShareShare
ReportReport
Posted on by 5

Hi All,

There are three methods you can use to work with the OnChange event for an attribute.

Could you please explain the below different methods, if possible please provide the Scenario based code.

  • CRM Naren Profile Picture
    CRM Naren 5 on at
    RE: Different methods of OnChange

    Yes

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Different methods of OnChange

    You are welcome! If my reply answered your question take a minute and click "Yes" under the question "Did this answer your question?".

  • CRM Naren Profile Picture
    CRM Naren 5 on at
    RE: Different methods of OnChange

    Thank you so Much for the information Andrew

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Different methods of OnChange

    Naren,

    That could be considered as examples.

  • CRM Naren Profile Picture
    CRM Naren 5 on at
    RE: Different methods of OnChange

    Hi Andrew,

    Greetings for the day!

    Thanks for your information.

    I saw some code snippet for the addonchange and Fireonchange functions can I consider the below as examples.

    pastedimage1593179888538v1.pngpastedimage1593179903007v2.pngpastedimage1593179913152v3.png

    Regards,

    Naren

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Different methods of OnChange

    Hello,

    You provided the urls for methods - that is great. If you will check the description at the top - it should be clear enough how every of method can be used:

    addOnChange - Sets a function to be called when the OnChange event occurs.

    example:

    function onNameChanged(executionContext){

    alert("name was changed");

    }

    //attach this function to onload event of the for and check "Pass execution context as a first parameter" checkbox

    function onLoad(executionContext){

    var formContext = executionContext.getFormContext();

    formContext.getAttribute("name").addOnChange(onNameChanged);

    }

    What this code does is following - during the load of the form code attaches onNameChanged function as a handle for onchange event of "name" field on the for.

    removeOnChange - Removes a function from the OnChange event hander for an attribute.

    it does opposite to the addOnChange - removes the handler from field. Example:

    function someFunction(executionContext){

    var formContext = executionContext.getFormContext();

    formContext.getAttribute("name").removeOnChange(onNameChanged);

    }

    fireOnChange - Causes the OnChange event to occur on the attribute so that any script associated to that event can execute.

    if you want to trigger event handler for the field when field value changes - you can use this method. Example:

    function someFunction(executionContext){

    var formContext = executionContext.getFormContext();

    formContext.getAttribute("name").fireOnChange();

    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans