Get 'dynamic old value' on client script

Dennis2
Kilo Expert

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.

1 ACCEPTED SOLUTION

SumanthDosapati
Mega Sage
Mega Sage

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

 

View solution in original post

1 REPLY 1

SumanthDosapati
Mega Sage
Mega Sage

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