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 

          

3 REPLIES 3

Tanushree Maiti
Kilo Sage

Please refer this links, see if it helps you:

approvals based on MRVS field value - ServiceNow Community

Please mark this response as Helpful and hit Like if it assisted you with your question.
Regards,
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

yashkamde
Tera Guru

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