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)

OnChange event firing after save if we change field value from javascript

(0) ShareShare
ReportReport
Posted on by 115

If I change a field value on form by java script then its onchange event is fired after Save. Can We stop onchange event to fire after save??

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at
  • AnkitSingh Profile Picture
    115 on at

    Hi have added this code on save

    function submitReadOnlyAttributes() {

       Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {

           var field = attribute.getName();

           if (Xrm.Page.getAttribute(field).getIsDirty() == true) {

               Xrm.Page.getAttribute(field).setSubmitMode("always");

           } else {

               Xrm.Page.getAttribute(field).setSubmitMode("dirty");

           }

       });

    }

    but still on change event fired after save.

  • Suggested answer
    Jitendra Sahu Profile Picture
    2 on at

    You may put below lines to overwrite existing funcationality of your control.

    var cntr=Xrm.Page.getControl("<your control Id>");

    cntr.setAttribute("onchange", function(){});

  • AnkitSingh Profile Picture
    115 on at

    I cannot overwrite the existing functionality.

    Suppose I have 2 fields and on-change of field 1 I populate the field 2 value. Field 2 also have the on-change function which is supposed to do something. When I save the form after save Field 2 event fire.

    How I stop this running after save and why this is running after save???

  • Sukh Gill Profile Picture
    967 on at

    Hi Ankit

    I am also experiencing this same issue where a fields OnChange event is fired after Save if the field value is dirty(Turbo Forms).  Did you manage to resolve this?

    Thanks
    Sukh

  • Verified answer
    AnkitSingh Profile Picture
    115 on at

    In my case the issue was with Guid which I was using in JS to set lookup value. From 2015 Update1 lookup Guid is case sensitive. So if you are using js to set lookups then use the function below:

    function SetLookupValue(LookupId, Type, Id, Name) {
        if (Id.indexOf('{') == -1)
            Id = '{' + Id;
        if (Id.indexOf('}') == -1)
            Id = Id + '}';
        Id = Id.toUpperCase();
    	var lookupReference = [];
        lookupReference[0] = {};
        lookupReference[0].id = Id;
        lookupReference[0].entityType = Type;
        lookupReference[0].name = Name;
        Xrm.Page.getAttribute(LookupId).setValue(lookupReference);
    }


    and this will solve the issue.

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