How to set a variable in Variable Set B from Variable Set A (g_form.setValue not working)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi ServiceNow Community,
I have a catalog item with two variable sets:
- Variable Set A (where my script runs)
- Variable Set B (contains the variable I need to update)
I’m using an onChange Catalog Client Script attached to a variable in Variable Set A. I’m trying to set a variable in Variable Set B (variable_b), which is a Select Box (Reference) variable.
Example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') return;
g_form.setValue('variable_b', 'test'); // doesn't change anything
}It runs without errors, but the value for variable_b doesn’t update.
Questions:
- Does a variable being in a different variable set affect how it’s referenced by
g_form.setValue()(or should the name work globally on the item)? - For a Select Box (Reference) variable, what value does
g_form.setValue()expect—display value (e.g.,"test") or the sys_id of the referenced record? - If it requires the sys_id, what’s the recommended way to set it from an onChange script (e.g., using
g_form.getReference()on another field, GlideAjax lookup, etc.)? - Are there timing/loading issues where the variable in Variable Set B isn’t ready yet during the onChange of Variable Set A?
Any working examples would be appreciated.
Notes:
- Script type: Catalog Client Script onChange
variable_btype: Select Box (Reference)
Thanks!
0 REPLIES 0
