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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Double alert onChange field

(0) ShareShare
ReportReport
Posted on by 71

Hello,

I've got the following javascript function called onChange event on the field:

function message() {
return alert("message");

}

The alert is shown correctly, while changing the field value, but also for the second time while saving the record. There is no onSave form script, as there are no more scripts on the form.

Appreciate your help on the matter.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Double alert onChange field

    Hi,

    If you haven't registered your method on save and if there is not other script on save which is changing the value of that field then you should not get the alert on save.

    can you share your script and some screenshot? It is possible that the onchange is getting triggered from some script.

    Do you get the alert if you just update/save the record (o.e. without changing the field)?

    Hope this helps.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at
    RE: Double alert onChange field

    Hi Pocia,

    This one is common if you have plugin that will change the property. So after on save, CRM will refresh the value and then trigger on change event. Please do check weather you have logic to change this property or not.

  • Pocia Profile Picture
    71 on at
    RE: Double alert onChange field

    Sure,

    Note, that there's only one script (mine) on the form. Field is named Description

    For onSave:

    1524.2018_2D00_03_2D00_26_5F00_03_2D00_14_2D00_51.jpg

    For onChange:

    1524.2018_2D00_03_2D00_26_5F00_03_2D00_14_2D00_51.jpg

    Script (this is literally whole script :) )

    2018_2D00_03_2D00_26_5F00_03_2D00_16_2D00_08.jpg

    And regarding your last question: alert shows only when changing the field, and while saving the record after changing the field. When changing other fields, alert doesn't show.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Double alert onChange field

    Hi,

    Can you remove the return keyword and try i.e.

    function disclaimer_text()

    {

    alert("hello");

    }

  • Pocia Profile Picture
    71 on at
    RE: Double alert onChange field

    Unfortunately, the error still exist :(

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Double alert onChange field

    Hi Pocia,

    am sorry but which error you are talking about. You mentioned the issue is that the message appears twice. Are you saying you now getting an error?

  • Suggested answer
    Abby Kong Profile Picture
    6 on at
    RE: Double alert onChange field

    Hi Pocia,

    Can you check inside plugin whether this field value is set again (even though still same value)?

    Search field name in plugin code, or test by disabling plugin steps related to this entity to locate the one causing problem.

    Regards,

    Abby

  • Feridun Kadir Profile Picture
    1,705 Most Valuable Professional on at
    RE: Double alert onChange field

    I had exactly this scenario recently. I proved to myself that the OnChange event was firing again after the record was saved but I think only for new records.

    I did not conclusively prove whether this is by design or an error. But, this link https://msdn.microsoft.com/en-gb/library/gg334481.aspx#BKMK_FieldOnChangeEvent says:

    "This event also occurs when data changes on the server are retrieved to update a field when the form is refreshed, such as after a record is saved."

    I wonder if that is causing the script to run again.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Double alert onChange field

    Hi Pocia,

    Go to form form designer -> form properties -> you can get  onload and onsave event there in the event section.

    Hope this helps.

  • Pocia Profile Picture
    71 on at
    RE: Double alert onChange field

    After playing around with script for a while, it's the latest version. Basically, it checks, whether there were performed changes to the field, and if field isn't empty show message:

    function disclaimer_text() {

    var dirty=Xrm.Page.getAttribute('description').getIsDirty();

    var value =Xrm.Page.getAttribute('description').getValue();

    if(dirty==1 && value != null){

    message();

    }

    }

    function message(){

    alert("msg");

    }

    However, there still is the double alert problem. When I'm filling the field with one line text, alert is shown once (onchange field event):

    2018_2D00_03_2D00_26_5F00_19_2D00_46_2D00_13.jpg

    But when I'm adding multiline text to the field, the alert is shown two times: onchange field event and onsave form event:

    2018_2D00_03_2D00_26_5F00_19_2D00_46_2D00_13.jpg

    Strange, isn't it? I honestly have no idea now what is going on :)

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans