Client Scripts for Multi-row Variable Sets
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 01:40 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2023 11:33 AM