Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Undo changes made On-Change of option set value

Posted on by 275

Hi
I have got a scenario where I'm letting user to update read only fields when a particular option set value is chosen(by enabling them). After changing the field values if the user selects another option(On change) I want to undo all the changes he have made. This is achievable on save but I want to do it on-change of the option set value. The option set got 4 values. I'm enabling the fields on-change of only one value, and have to revert the changes when any of remaining 3 option values are chosen. Thank you.

*This post is locked for comments

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Undo changes made On-Change of option set value

    You can also create an array of key/value pairs that will store the field name and the field value when the form is loaded.

    var attributes = Xrm.Page.data.entity.attributes.get();

      for (var i in attributes) {

       attributeName = attributes[i].getName();

        attributeValue = attributes[i].getValue();

       // Add attributeName and Value to your collection and store in array variable

    }

    You can use the getAttributeType to check the attribute if you want to restrict which ones you add to the array.

    If you need to revert the changes, you loop through the attribute collection and make the changes to your fields, since you are storing the name of the attribute

    Basically foreach element in the array

    Xrm.Page.getAttribute(attributeName).setValue(attributeValue);

    Refer to the following for more information on the functions available on the attributes and collections:

    msdn.microsoft.com/.../gg334409.aspx

    Hope this helps.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Undo changes made On-Change of option set value

    Hi,

    As you need to store the original field values, you would need to have some placeholders for this. The options (other than global variable) would be to have additional field for each field which would store the actual database value (i.e. actual field & form field).  

    However, I believe the best option for you is to use the global variables as suggested above. This is because you can copy paste the code. Creating 60+ field is a task in itself.

    Hope this helps

  • Turbo Forms Profile Picture
    Turbo Forms 275 on at
    RE: Undo changes made On-Change of option set value

    Hi CLAB, I got around 60+ editable fields that will be enable to be edited. Is there any other way instead of setting global variables? Thank you

  • Suggested answer
    Ivan Ficko Profile Picture
    Ivan Ficko 1,380 on at
    RE: Undo changes made On-Change of option set value

    You can save the previous value to a variable(s) in JavaScript. If the value of the option set is again changed to one of the 3 values just change fields to the values you have stored in variable(s).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Undo changes made On-Change of option set value

    Hi ,

    What you can try is to create a global javscript objects for each field .

    On-load of the form , onlaod event => you save the original values of the fields in these global objects .

    va globalVar2 = Xrm.Page.getAttribue(field1).getValue();

    va globalVar2 = Xrm.Page.getAttribue(field2).getValue();

    va globalVar3 = Xrm.Page.getAttribue(field3).getValue();

    then whenver you need to resotre the original values , you can use these objects.

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans