web
You’re offline. This is a read only version of the page.
close
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.

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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();

    }

  • CRM Naren Profile Picture
    5 on at

    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
    84,331 Most Valuable Professional on at

    Naren,

    That could be considered as examples.

  • CRM Naren Profile Picture
    5 on at

    Thank you so Much for the information Andrew

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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
    5 on at

    Yes

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans