Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Clear variable values on realtime

rah dev
Tera Contributor

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

rahdev_0-1776933941576.png


thanks

1 REPLY 1

pr8172510
Giga Guru

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:

pr8172510_0-1776938609904.pngpr8172510_1-1776938637278.png

pr8172510_2-1776938679428.png

 

 

 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