Set an MRVS Variable Based on an Outside Variable in ServiceNow

vsrahul127
Kilo Contributor

Hi Community,

Sharing a solution for a widely asked requirement in servicenow, where we need to set the value of a variable inside a Multi-Row Variable Set (MRVS) based on the value of a variable outside the MRVS.

Requirement

In a ServiceNow Catalog Item, suppose we have a variable outside the MRVS and we want to populate its value into a variable inside the MRVS.

For example:

Outside variable: outside_variable
MRVS variable: mrvs_variable

Whenever the MRVS loads, the value from the outside variable should be automatically populated into the corresponding MRVS variable.

Solution

This can be achieved using an OnLoad Catalog Client Script on the MRVS.

Use the following script:

var appValue = g_service_catalog.parent.getValue('backend_variable_name_of_the_outside_variable');

if (appValue) {
g_form.setValue('variable_name_of_mrvs', appValue);
}



0 REPLIES 0