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.

1 REPLY 1

Tanushree Maiti
Tera Guru

Hi Harshini,

Last week in our project ,we have been working with MRVS which was having couple of other variables . On sc_task , we did not face any issue on data population. Only thing is that to make MRVS mandatory UI policy did not work on sc_task.

After following this KB article(https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1005265),  we were sorted!

 

 


Please mark this response as helpful and hit Like if it assisted you with your question.


Thanks,
Tanushree
Certified Technical Architect | 9xCIS