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
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.
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
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
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).
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156