Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Client Scripts for Multi-row Variable Sets

rui031
Tera Contributor

Client Scripts for Multi-line Variable Sets

After selecting variable A reference item in a variable set, I want to automatically input the value of the A-B item associated with the reference record into variable B item. This is why the OnChange script.
We have already created a client script that can achieve the above in the incident form. However, when I use this script in a variable set, it does not work well.

The script is below for reference.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

// Need to get the form value, in case it changes but then changes back to value in database (oldValue is always DB value)
if (oldValue ! = newValue)
A = newValue;

if (oldValue ! = newValue || newValue ! = g_scratchpad.A) {
var lookupGr = new GlideRecord('u_cmdb_host');
lookupGr.addQuery('sys_id', newValue);
lookupGr.setLimit(1);
lookupGr.query(lookupCallback);
}
}

function lookupCallback(lookupGr){
if (lookupGr.next()) {
g_form.setValue('B', lookupGr.A-B);

}
}

Can someone please help me out.
Thanks in advance!

1 REPLY 1