Onchange Client script previous value

BenG
Tera Guru

Hello,

Is there a way to catch the previous value of a Onchange client script ?

Not the oldValue (first value after a page load) by the previous value after the newValue ?

I did that with a custom field "previous value" who copy the newValue every time to compare with the value of the field "previous value".

It works well by I would like to know if there is a better way to do that stuff. (I don't wont to create fields everytime I need a previous value ;-))

Thanks a lot for your help.

Regards, 

7 REPLIES 7

Hi Ben,

I don't think using the client script you would get that directly

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

arth
Tera Contributor

Hi Ben,

 

Have you tried adding scratchpad in the end of the onChange Client Script to store the previous value?

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;
}

Karn2
Kilo Contributor

Thanks Arth,

This was really Helpful.