- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 01:43 AM
Hi everyone,
When I use a client script, in a onChange client script, newValue has the last value in the field but oldValue is the current value saved in that field on this record.
For example: First change: Field A, from '1' to '2' --> oldValue = 1, newValue = 2
Second change (without saving form): Field A, from '2' to '3' --> oldValue = 1, newValue = 3.
In this second change, is there any way to get the 'dynamic old value' as '2'?
Thanks in advance.
Dennis.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 02:54 AM
Hi Dennis,
For your case
Approach 1: If you want only the last updated value in that field then try this.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var previousValue;
if (g_scratchpad.previousValue == undefined){
previousValue = oldValue;
}
else{
previousValue = g_scratchpad.previousValue;
}
g_scratchpad.previousValue = newValue;
// write your main code here and use previousValue to get the last changed value
}
Now 'previousValue' will have the value you are expecting
Approach 2: If you want all the values oldValues selected in the field onChange
you can declare an empty array and push the newValue into it always when the client script is executed.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 02:54 AM
Hi Dennis,
For your case
Approach 1: If you want only the last updated value in that field then try this.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var previousValue;
if (g_scratchpad.previousValue == undefined){
previousValue = oldValue;
}
else{
previousValue = g_scratchpad.previousValue;
}
g_scratchpad.previousValue = newValue;
// write your main code here and use previousValue to get the last changed value
}
Now 'previousValue' will have the value you are expecting
Approach 2: If you want all the values oldValues selected in the field onChange
you can declare an empty array and push the newValue into it always when the client script is executed.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth