- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi everyone, I am working on a ServiceNow catalog item where I have a multi row variable set named specify and inside it a user reference variable name_3, and I am using a catalog client script onChange to populate a catalog-level variable uvar which works correctly when I add or update a user, but when I remove a row using the delete icon the onChange script does not trigger and the value in uvar is not cleared, I have tried handling empty values and using clearValue in the same script but it does not execute on row removal, so I want to know what is the recommended or best practice way to detect MRVS row deletion and clear the parent variable immediately using catalog client scripts without using service portal widgets or polling.
script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;
alert("MRVS field changed: " + newValue);
// From MRVS → Parent form variable
if (typeof parent !== 'undefined' && parent.g_form) {
parent.g_form.setValue('uvar', newValue);
alert("uvar populated successfully: " + newValue);
} else {
// fallback (rare case)
g_form.setValue('uvar', newValue);
}
}
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @rah dev ,
This behavior is expected in ServiceNow. Deleting a row from a Multi Row Variable Set (MRVS) does not trigger onChange client scripts, so handling it in real-time is not possible using standard client scripting.
I implemented a working solution using onLoad + onSubmit client scripts:
Approach:
- Fetch MRVS value using:
g_form.getValue('specify') - Parse it using JSON.parse()
- Check if rows exist
Logic:
- If MRVS is empty → clear parent variable (uvar)
- If MRVS has data → set value from first row (name_3)
Scripts Used:
onLoad:
- Ensures correct value when form loads
onSubmit:
- Ensures value is updated/cleared before submission
Result:
- When MRVS row is deleted → value is cleared after submit
- When MRVS has value → parent variable is populated correctly
- Verified on RITM record as wel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @rah dev ,
This behavior is expected in ServiceNow. Deleting a row from a Multi Row Variable Set (MRVS) does not trigger onChange client scripts, so handling it in real-time is not possible using standard client scripting.
I implemented a working solution using onLoad + onSubmit client scripts:
Approach:
- Fetch MRVS value using:
g_form.getValue('specify') - Parse it using JSON.parse()
- Check if rows exist
Logic:
- If MRVS is empty → clear parent variable (uvar)
- If MRVS has data → set value from first row (name_3)
Scripts Used:
onLoad:
- Ensures correct value when form loads
onSubmit:
- Ensures value is updated/cleared before submission
Result:
- When MRVS row is deleted → value is cleared after submit
- When MRVS has value → parent variable is populated correctly
- Verified on RITM record as wel
