Multi row variable set (MRVS) not visible in catalog task

sutot
Tera Contributor

Hi all,

I have a catalog item with a MRVS (called u_tokens) and I want to display it in the corresponding RITMs and SCTASKs.

Before it was ok, but after the upgrade from New York to Paris, the MRVS is not displayed in the SCTASK form.

After some investigation, I realized that:

1. MRVS variables cannot be set as 'Global'

2. UI policy 'Visible' action does not work with MRVS (see UI Policy.png attachment)

3. If the SCTASK is created by using a 'Catalog task' activity in the workflow editor, all MRVS - if selected - are correctly displayed in the SCTASK form (see Catalog task activity.png attachment).

Applying the point 3 would resolve my issue, but unfortunately I have a lot of workflows and business rules that create SCTASKs via script. Do you have any idea how can I resolve my problem? Is there some command I can use in scripts to make MRVS visible in tasks?

Thank you,

Sutot

 

1 ACCEPTED SOLUTION

Suseela Peddise
Kilo Sage

Hi,

You can write below script in business rule to display MRVS variables and their values in catalog task variable editor

 

(function executeRule(current, previous /*null when async*/) {

// Copies the values from a multi-row variable set into a variable so we can view the values on a catalog task.
var variables = [];
var catItem = current.request_item.cat_item.toString();
var variableSets = [];
var getVariableSets = new GlideRecord('io_set_item');
getVariableSets.addQuery('sc_cat_item',catItem);
getVariableSets.query();
while(getVariableSets.next()) {
variableSets.push(getVariableSets.getValue('variable_set'));
}
var getCatalogVariables = new GlideRecord('item_option_new');
var qry='cat_item='+catItem
+'^active=true'
+'^NQvariable_set.sys_idIN'+variableSets.toString()
+'^active=true';
getCatalogVariables.addQuery(qry);
getCatalogVariables.query();
while(getCatalogVariables.next()) {
variables.push(getCatalogVariables.getValue('sys_id'));
}
var variablesCount = variables.length;
var currentTaskID = current.sys_id.toString();
for(var i=0;i<variablesCount;i++)
{
var getTaskVars = new GlideRecord('sc_item_variables_task');
getTaskVars.addQuery('task',currentTaskID);
getTaskVars.addQuery('variable',variables[i]);
getTaskVars.setLimit(1);
getTaskVars.query();
if(!getTaskVars.hasNext())
{
getTaskVars.initialize();
getTaskVars.setValue('task',currentTaskID);
getTaskVars.setValue('variable',variables[i]);
getTaskVars.insert();
}
}
})(current, previous);

 

If I have answered your question, please mark my response as correct and/or helpful.

 

Thanks,

Suseela P.

View solution in original post

10 REPLIES 10

sutot
Tera Contributor

Dear Suseela,

Your suggestion works! I only made some changes in the queries in order to get only MRVS variables and to leave all other variables managed by the 'Global' field.

Thank you,

Sutot

(function executeRule(current, previous /*null when async*/) {

// Copies the values from a multi-row variable set into a variable so we can view the values on a catalog task.
var variables = [];
var catItem = current.request_item.cat_item.toString();
var variableSets = [];
var getVariableSets = new GlideRecord('io_set_item');
getVariableSets.addQuery('sc_cat_item',catItem);
getVariableSets.addQuery('variable_set.type','one_to_many'); //get only MRVS variable sets
getVariableSets.query();
while(getVariableSets.next()) {
variableSets.push(getVariableSets.getValue('variable_set'));
}
var getCatalogVariables = new GlideRecord('item_option_new');

var qry='variable_set.sys_idIN'+variableSets.toString()+'^active=true'; //get only variable in MRVS variable sets

getCatalogVariables.addQuery(qry);
getCatalogVariables.query();
while(getCatalogVariables.next()) {
variables.push(getCatalogVariables.getValue('sys_id'));
}
var variablesCount = variables.length;
var currentTaskID = current.sys_id.toString();
for(var i=0;i<variablesCount;i++)
{
var getTaskVars = new GlideRecord('sc_item_variables_task');
getTaskVars.addQuery('task',currentTaskID);
getTaskVars.addQuery('variable',variables[i]);
getTaskVars.setLimit(1);
getTaskVars.query();
if(!getTaskVars.hasNext())
{
getTaskVars.initialize();
getTaskVars.setValue('task',currentTaskID);
getTaskVars.setValue('variable',variables[i]);
getTaskVars.insert();
}
}
})(current, previous);

DiNesh77
Tera Contributor

Hi Sutot,

Will the above script work only after insert in BR?.

Because i am trying it in before insert and it does not work.

As per my requirement i am trying to push the MRVS before the catalog task gets inserted.

Any idea on how to fix this issue?

 

michellelim
Tera Expert

Does anyone know if this will be available in Quebec or future release? To get MRVS in sc_task without having to write the function ?

@michellelim 

Are you not able to select the MRVS variable set in the catalog task activity so that you can push it from Available to Selected section?

I was able to do that in Quebec and it shows MRVS in catalog task

Refer below example; I tested this in my PDI Quebec and worked fine

Catalog Task Activity - I moved that variable set from Available to Selected

Catalog Task created from workflow has that MRVS Variable set on Variables section

 

Regards
Ankur

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

Hi @Ankur Bawiskar @michellelim 

 

 I recently came across this issue and I noticed that when we have SC Catalog Item Deprecated widget, then this MRVS not works even in Quebec version. Where as if it is SC Catalog Item widget latest, then this MRVS shows on catalog task. 

I tried to use the latest SC Catalog Item widget, but I am facing different issue which is once the ticket is submitted, it is not redirecting to the Ticket page. Still struggling to fix this though. Let me know if you have any fix incase.