Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Flow to display Multi Row Variable Set for all catalog items

JuanMosquella
Tera Contributor

I've created a flow which uses Create Catalog Task action to take a multi row variable set and show it on catalog task, but this only works for a specific catalog item, is there a way to make this flow dynamic so it works for all catalog items with MRVS within it?

JuanMosquella_0-1751478966904.png


This is the MRVS added to the catalog task

JuanMosquella_1-1751478994714.png

 

As you can see, you are forced to pick a specific catalog item and map the MRVS to show it on Catalog Task, but I need to achive the same for all catalog items with MRVS so all of them use the same flow.
So far I was able to get the MRVS as json using scripting, but I dont know how to use it or display the MRVS when creating a catalog task using this method

This is the script:

(function execute(inputs, outputs) {
    var reqItemGR = new GlideRecord('sc_req_item');  

    var catItemSysId = reqItemGR.cat_item;
    var variableSets = [];
    
    // Find variable sets linked to the catalog item
    var catItemVars = new GlideRecord('item_option_new_set');
    catItemVars.addQuery('cat_item', catItemSysId);
    catItemVars.query();

    while (catItemVars.next()) {
        if (catItemVars.type == 'multi_row') {
            var setName = catItemVars.name.toString();
            var mrvsData = reqItemGR.variables[setName];
            if (mrvsData) {
                try {
                    var parsed = JSON.parse(mrvsData);
                    variableSets.push({
                        name: setName,
                        label: catItemVars.getDisplayValue('name'),
                        data: parsed
                    });
                } catch (e) {
                    variableSets.push({
                        name: setName,
                        error: 'Failed to parse MRVS JSON'
                    });
                }
            }
        }
    }

    outputs.mrvs_json = JSON.stringify(variableSets);

})(inputs, outputs);




1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@JuanMosquella 

Ideally you should do this within the Flow action itself to stay to out of the box. I will recommend this approach only.

to add MRVS on catalog task in general check this link which has script

Displaying Multi-Row Variable Sets on Catalog Tasks 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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