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)

Undo changes made On-Change of option set value

(0) ShareShare
ReportReport
Posted on by 277

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    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.

  • Suggested answer
    Ivan Ficko Profile Picture
    1,380 on at

    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).

  • Turbo Forms Profile Picture
    277 on at

    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
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

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