Multi Row Variable Set (MRVS) Not Working on Catalog Task? Here’s What Finally Worked

HarshiniReddy
Tera Contributor

I want to share something that took me way more time than expected to figure out — accessing Multi Row Variable Set (MRVS) data on Catalog Tasks (SCTASK). 


One key confusion point was this: it’s not like normal variables, where simply setting the variables in a variable set to “Global = true” makes them visible on Catalog Tasks. That approach works for many regular variables — but MRVS behaves differently. In fact, MRVS variables can’t be made global at all, so that usual fix won’t help, and you need a different approach.


So posting this here in case it saves someone else a few hours of debugging.


The Problem

When working on a Catalog Task, trying to access MRVS using: 

current.variables.<mrvs_name>

either returns empty or doesn’t behave as expected — because MRVS data is stored differently.

Catalog Tasks don’t directly hold MRVS rows like RITM does.


What Finally Worked for Me

After trying multiple scripting approaches, I implemented an After Insert Business Rule on Catalog Task to map MRVS variables to the task using sc_item_variables_task.

This makes MRVS variables accessible directly at the Catalog Task level.
 

Business Rule Details

  • Table: sc_task
  • When: after insert


Script Used


(function executeRule(current, previous) {

var variables = [];
var catItem = current.request_item.cat_item.toString();
var variableSets = [];
// Get MRVS variable sets linked to catalog item
var getVariableSets = new GlideRecord('io_set_item');
getVariableSets.addQuery('sc_cat_item', catItem);
getVariableSets.addQuery('variable_set.type', 'one_to_many');
getVariableSets.query();

while (getVariableSets.next()) {
        variableSets.push(getVariableSets.getValue('variable_set'));

// Get variables inside MRVS
var getCatalogVariables = new GlideRecord('item_option_new');
getCatalogVariables.addQuery('variable_set.sys_id', 'IN', variableSets.join(','));
getCatalogVariables.addQuery('active', true);
getCatalogVariables.query();

while (getCatalogVariables.next()) {
         variables.push(getCatalogVariables.getValue('sys_id'));
}

// Map variables to catalog task
for (var i = 0; i < variables.length; i++) {
var getTaskVars = new GlideRecord('sc_item_variables_task');
getTaskVars.addQuery('task', current.sys_id);
getTaskVars.addQuery('variable', variables[i]);
getTaskVars.query();

if (!getTaskVars.hasNext()) {
       getTaskVars.initialize();
       getTaskVars.task = current.sys_id;
       getTaskVars.variable = variables[i];
       getTaskVars.insert();
}
}

})(current, previous);


P.S. This is based on what worked for me after quite a bit of trial and error. If anyone has any other working approaches, I’d love to hear them — always happy to learn from the community.

7 REPLIES 7

Ankur Bawiskar
Tera Patron

@HarshiniReddy 

MRVS can be shown on catalog task Form when Catalog Task is created via Workflow or Flow

what didn't work for you?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

The Catalog task was created through scripting and Workflow Lookup rather than the standard “Create Catalog Task” activity.

Hi Ankur,

The Catalog task was created through scripting and Workflow lookup rather than the standard "Create Catalog Task" activity.