Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Status Reason field on Incident entity

Posted on by 160

I am using status reason field on Incident entity. There is a function written on change of the field value.

if (statusValue == 2)

{

Xrm.Utility.alertDialog("Cannot set this value", function () {

// Change the status to previous value
Xrm.Page.getAttribute(constants.statuscode).setValue(1);

});

The function triggers thrice when we set the value of the field. The function triggers once when we don't reset the old value.

Can anyone provide a workaround for it or reason why it is happening?

*This post is locked for comments

  • Krishna Bhanushali Profile Picture
    Krishna Bhanushali 160 on at
    RE: Status Reason field on Incident entity

    @Prawel: Using a global variable did not help. Only for the first time, it worked properly but if status field is changed again it is not working and I can see the function triggering thrice.

    I made use of setFormNotification instead of alertDialog and cleared the notification while save of the record.

  • Krishna Bhanushali Profile Picture
    Krishna Bhanushali 160 on at
    RE: Status Reason field on Incident entity

    I noticed that on every field it triggers twice. Whether its Option set field or string field.

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Status Reason field on Incident entity

    Hi,

    The reason why it's triggering twice is because you are setting this value in JS and it triggers OnChange event again. This is a clear bug of new Turbo-Forms. If you switch to "legacy" mode of form rendering (in System Settings) it will be triggered only once. If you want to keep the turbo forms, I suggest that you make a global variable in JS to prevent OnChange propagation. Something like that (it's simplified for you to get the idea):

    var stopPropagation = false;
    
    function OnChange(){
        if(stopPropagation){
    stopPropagation = false;
    return; }

    stopPropagation = true;
    SetValue("statuscode", 1) // this will again fire Onchange but will stop because of the lines above }


  • Suggested answer
    Sartaj Profile Picture
    Sartaj 880 on at
    RE: Status Reason field on Incident entity

    Hi Krishna,

    Setting value programmatically ( in your case setting status reason back to 1) should not cause onChange event to fire.

    There was an issue with turbo form rendering engine came with CRM 2015 UP1. Setting value programmatically was causing change event to fire.

    As a workaround you can do the following steps if the issue in your case is due to bug.

    1- Go to Settings area , click Administration then System Settings.

    2- With in General tab of system setting form scroll down and set "Use Legacy Form Rendering" to Yes.

    3- Click OK to save the setting m reload browser and test you code.

    Regards,

    Sartaj

  • Suggested answer
    Nikica Profile Picture
    Nikica 307 on at
    RE: Status Reason field on Incident entity

    Hi,

    I think It is called twice because the StatusReason actually changes two times - first time by the user, second time by JavaScript.

    I see two workarounds:

    1) maybe, first answer in this topic could help http://stackoverflow.com/questions/20453320/dynamically-change-option-set-values-in-crm

    2) If StatusReason can't be controlled in the way described in 1):

    i -Hide StatusReason field

    ii - add an optionset field that acts as StatusReason (has same values and labels as status Reason)

    iii - manage it in the way described in 1) (that means hide option status code2 when needed)

    iv -  whenever the field changes, update Status Reason appropriately.

    Of curse, I assume you can't delete the StatusReason value (through customisations->Entity->Fields) for some reason. Otherwise, delete the value you don't need.

  • Krishna Bhanushali Profile Picture
    Krishna Bhanushali 160 on at
    RE: Status Reason field on Incident entity

    Hi Nithya,

    I am already using Transitions

    Can you provide me with something else.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
  • Krishna Bhanushali Profile Picture
    Krishna Bhanushali 160 on at
    RE: Status Reason field on Incident entity

    1) if (statusValue == 2)

       {

       Xrm.Utility.alertDialog("Cannot set this value", function () {

       });

    The above function is triggered only once when the status reason field value is changed.

    2) if (statusValue == 2)

      {

      Xrm.Utility.alertDialog("Cannot set this value", function () {

      Xrm.Page.getAttribute(constants.statuscode).setValue(1);

      });

    The above function is triggered for 3 times and I can see the alert for 3 times.

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Status Reason field on Incident entity

    Hi Krishna,

    Can you please explain the scenario?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans