We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to trigger approvals based on multi row variable set values

Meenal1
Tera Contributor

Hi Team,

 

How to trigger approvals based on Multi Row variable values ?I have a requirement where user can select multi System IDs and based on that it show trigger approval in the flow designer and once approved appropiate catalog task should open. To get approval user and assignment group I have create a custom matrix table based on country region environment and system ID appropriate approval should trigger But If the approval is triggered to the same user then only trigger 1 approval for that.

 

Similarly once approved it should create catalog task if the assignment group is same for multiple system Id then it should trigger only 1 catalog task , but if it is triggered to fifferent group than create 2 tasks.

 

 

Example MrvS: system Dev 21 - approver abc

                     system QQ31 - approver abc 

                     system dev12 - approver xyz (in this case it should trigger 1st approval to abc and 2nd to xyz) it should create two approvals for abc.

Similary for catalog task.

 

Kindly help to design this. I'm using flow designer for the same currently i'm not able to avoid same approvals 

 

my flow snippet

Best Regards,

meenal 

          

7 REPLIES 7

Tanushree Maiti
Giga Sage

Please refer this links, see if it helps you:

approvals based on MRVS field value - ServiceNow Community

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

yashkamde
Kilo Sage

Hello @Meenal1 ,
Since MRVS data comes as JSON, the first step is to read and loop through each MRVS row in Flow Designer using a Script step.

So according to your example :

  • Systems Dev21 and QQ31 both map to abc → only one approval
  • System Dev12 maps to xyz → second approval created
  • Same logic applies to catalog tasks

So in flow designer Use script step :

(function execute(inputs, outputs) {

    var mrvs = JSON.parse(inputs.mrvs); // MRVS JSON
    var approverMap = {};
    var groupMap = {};

    mrvs.forEach(function(row) {

        var gr = new GlideRecord('u_approval_matrix');
        gr.addQuery('u_system_id', row.system_id);
        gr.addQuery('u_country', row.country);
        gr.addQuery('u_region', row.region);
        gr.addQuery('u_environment', row.environment);
        gr.query();

        if (gr.next()) {
            // avoid duplicate approvals
            approverMap[gr.u_approver.toString()] = true;

            // avoid duplicate catalog tasks
            groupMap[gr.u_assignment_group.toString()] = true;
        }
    });

    outputs.approvers = Object.keys(approverMap);
    outputs.groups = Object.keys(groupMap);

})(inputs, outputs);

 

How to use this in Flow :

  • Use For Each → approvers → Create Approval

  • Use For Each → groups → Create Catalog Task

That’s it.
If my response helped mark as helpful and accept the solution.

Hi @yashkamde ,

 

Thank you for replying.

what to pass in row. systemID is that a input variable ?

 

How to use this in flow ?

After for each step should I include this script action and then Ask for approval action?

 

Best Regards,

\Meenal 

Yes @Meenal1 , [row. systemID] will be in mrvs input variable, through the script action we will extract it..

-> So make one script action take input as json and pass mrvs to it..

-> The script will output two arrays: approvers and groups.

so the flow will look like these:

1) Script Action (parse MRVS, build approvers/groups arrays)

2)For Each (approvers) → Ask for Approval

3)For Each (groups) → Create Catalog Task

 

If my response helped mark as helpful accept the solution.