Siddhesh Gawade
Mega Sage

Introduction
When building catalog items with Multi-Row Variable Sets (MRVS) in ServiceNow, you often need to propagate a selection/change inside a MRVS row to variables/fields on the parent Record. MRVS variable scripts run inside an iframe; to read or write the parent record's variables or fields you must use parent.g_form

Example — How It Works

  • Concept: Read the current MRVS row values with local g_form.getValue('variable_name'), and set parent RITM variables with parent.g_form.setValue('variable_name').

 

  • Minimal OnChange Catalog Client Script example on MRVS:
    function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') return;
    
    // read row-level values (local g_form)
    var Account= g_form.getValue('company');
    
    // set parent RITM variables so the values are available on the Parent form / RITM record
    parent.g_form.setValue('selected_company', Account);
    
    }​

 

Summary

  • Use parent.g_form inside MRVS client scripts to read/write RITM variables and keep MRVS state synchronized with the parent record.

 

  • Workflow-friendly pattern: read row values (local g_form), modify MRVS JSON on the parent, then update parent variables via parent.g_form.setValue(...).

 

  • Keep parsing safe, avoid heavy logic on the client, and use server-side validation for authoritative checks.

Comments
Brad Bowman
Kilo Patron

It's important to note that due to architecture, this method does not work outside of the native UI, so Service Portal, Employee Service Center, and all future workspaces require a different approach.

 

Here's an example of the same script that will work in all UIs, once the additional action that follows is taken:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') return;

    // read row-level values (local g_form)
    var Account= g_form.getValue('company');

    // set parent RITM variables so the values are available on the Parent form / RITM record
    if (this) { //Service Portal, etc. method
        this.cat_g_form.setValue('selected_company', Account);
    } else { //native UI method
        parent.g_form.setValue('selected_company', Account);
    }
}

To get this to work, you also need an onLoad Catalog Client Script that applies to the Catalog Item, not the MRVS:

function onLoad() {
    if (this) { //we only need to do this for Service Portal
        //We need to make the g_form object for the parent item available from the MRVS window
        this.cat_g_form = g_form;
    }
}

 

Siddhesh Gawade
Mega Sage

Hello @Brad Bowman  ,

 

Thank for this additional information 😊

Matthew_13
Kilo Sage

Great share; Looking forward to more!

Version history
Last update:
3 weeks ago
Updated by:
Contributors