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 :
Microsoft Dynamics CRM (Archived)

Field Javascript OnChange event fired when form loaded

(0) ShareShare
ReportReport
Posted on by 102

This may seem like a simple one, but I cant find the right answer from all my searches

I have a JS function that is called form a field OnChange event that I only want to run when the user actually changes the values.

Currently it also calls the function when the form is loaded. Is there any way to ensure that this function is only called when the user performs the change in the form?

Nick

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ajyendra Profile Picture
    1,738 on at

    Hi,

    It probably because in load you set that field or you Change on that field on Form Load . So that it will call onChange function.

    Can you share us webresources where you wrote both Onload and OnChange Code(full Code) that might help to figure out easily.

    Thanks

    Ajyendra

  • Verified answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at
    Hi,
    Please go to onchange event of the desired field and call the function. Do not add it on onload event so that it will be triggered only on onchange event and not on onload event.
    Please check the following link for your reference
  • Verified answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    Hi,

    ajyendra is correct. If in onload you have function that will change another property. That event will be triggered also. It's because since 2016, Crm adding function to trigger related event on the attribute also. So if you don't want to be triggered from OnLoad, you need to add flag to differentiate between called from onload or on the event itself. Example:

    var isFromOnLoad;
    
    function onLoad() {
     isFromOnLoad = true;
     ...
     Xrm.Page.getAttribute('attribute1').setValue(1);
     isFromOnLoad = false;
    }
    
    function attribute1OnChanged() {
     if(isFromOnLoad) return;
     //do attribute1onchanged
    }

  • nwood Profile Picture
    102 on at

    I found the issue:

    I am using the Dependant Optionset JS library to filter parent/child related optionsets. In order to set the filter on load, it calls:

    parentAttribute.fireOnChange

    I now need to figure out how to use this library with the onchange function for the target field

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans