Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

If multiple locations are selected then send approvals in parallel

DeIvory Gordon
Tera Guru

Hello, 

 

I created a catalog item and added a Location dropdown selection with 4 options (Bardon, Cambridge Gateshead and Leeds). 

 

I created 4 approval requests on the flow:

If Bardon is selected then an approval is sent to Tensor-UKBAR1-Approvers

If Cambridge is selected then an approval is sent to Tensor-UKCAM1-Approvers
If Gateshead is selected then an approval is sent to Tensor-UKGAT1-Approvers
If Leeds is selected then an approval is sent to Tensor-UKLEE1-Approvers

 

If multiple locations are selected then I need to send approvals in parallel (for example, if Gateshead and Bardon are selected then send two separate approvals to Tensor-UKGAT1-Approvers and Tensor-UKBAR1-Approvers (I am not sure how to set up this part).  Any help you can give is greatly appreciated, thanks!

2 REPLIES 2

Rafael Batistot
Kilo Patron

Hi @DeIvory Gordon 

This article might help you 

https://www.servicenow.com/community/itsm-forum/parallel-approvals-in-flow-designer-proposed-solutio...

If this response was helpful, please mark it as Helpful and, if applicable, as Correct.
This helps other users find accurate and useful information more easily

Shahjay
Kilo Guru

Hi @DeIvory Gordon,

 

A Select Box only holds one value, so you'll need to change Location to a List Collector on cmn_location (filtered to your four sites) before anyone can pick more than one.

 

I'd steer away from putting several Ask for Approval actions inside a "Do the following in parallel" block on the same RITM. Each one sets up a watcher on the same record, so when one group approves, the others can think they're done too and move on early.

 

What works better is a single Ask for Approval action with a scripted rule. Add the action on the Requested Item, click the f(x) toggle on the Rules input and paste this in. Swap the placeholders for your real location and group sys_ids, and change "locations" if your variable has a different name.

 

var map = { 'BARDON_LOC_ID':'UKBAR1_GRP_ID', 'CAM_LOC_ID':'UKCAM1_GRP_ID', 'GAT_LOC_ID':'UKGAT1_GRP_ID', 'LEE_LOC_ID':'UKLEE1_GRP_ID' };

var locs = (fd_data.trigger.request_item.variables.locations + '').split(',');

var grps = [];

locs.forEach(function (l) { l = l.trim(); if (map[l]) grps.push(map[l]); });

if (!grps.length) return '';

var rule = grps.map(function (g, i) { return (i ? '&AnyG[' : 'ApprovesAnyG[') + g + ']'; }).join('');

return rule + 'OrRejectsAnyG[' + grps.join(',') + ']';

 

So if someone picks Gateshead and Bardon, the rule comes out as ApprovesAnyG[gateshead group]&AnyG[bardon group]OrRejectsAnyG[gateshead group,bardon group]. AnyG means one person from that group is enough, the & means every selected group has to approve, and the OrRejectsAnyG part means a rejection from any of them rejects the whole request. Both groups get their approvals at the same time, and the flow waits until they've all signed off. After the action, add an If on its Approval State output to handle approved and rejected.

 

If you'd prefer four checkboxes over a List Collector, the same idea works. Just check each checkbox in the script and add that site's group to grps when it's true.

 

When testing, try one location first, then two, and make sure both approvals sit in Requested until each group acts. If the action comes back as Skipped with no approval records, add gs.info(rule) before the return and compare it with the rule the builder creates when you set it up by hand. Usually it's a stray space in a sys_id, a group with no active members, or nothing matching the map.

If this response helped, please mark it as correct and close the thread ✅ — it helps future readers find the solution faster.

Thanks