I have an optionset field in an entity, I want to fire a JavaScript method on this field change. I want to capture the old value of the field on the change. I've got a solution which gets the old value on form load, but this doesn't work on multiple changes.
Asked
Active
Viewed 2,705 times
0

Arun Vinoth-Precog Tech - MVP
- 22,364
- 14
- 59
- 168

khaled rimawi
- 55
- 1
- 8
-
Can you out codes for clarity? – lambda Apr 01 '19 at 08:11
1 Answers
2
This has to be solved by our own code implementation. Store the attribute value on form load in a variable, keep the new value in that variable on every change, so you can use that in onChange
handler. At the end of business validation inside handler put that new value in variable if success or revert to old value if failed.
var previousValue;
function onFormLoad(){
previousValue = formContext.getAttribute("fieldname").getValue();
}
function onFieldChange(){
if(myBusinessValidationSucceeds){
previousValue = formContext.getAttribute("fieldname").getValue();
}
}

Arun Vinoth-Precog Tech - MVP
- 22,364
- 14
- 59
- 168