The Zurich release has arrived! Interested in new features and functionalities? Click here for more

For Each Logic In Flow Designer

ammar_k
Tera Contributor

Hello everyone,

I have a field of type List on my Project form that allows selecting multiple managers (users).
What I’d like to achieve is:

  • When the project is submitted (or reaches a certain state),

  • An approval request is sent to each manager that was selected in this list field.

I’m not sure what is the best way to configure this. for each logic doesn't seem to work

Has anyone implemented something similar, or can share best practices for this scenario?

Thanks in advance!

 

5 REPLIES 5

Nawal Singh
Tera Expert

Hi @ammar_k ,

 

I have created the same scenario and tested it in my PDI (list type field and selected multiple managers) and i'm able to send the approval to all the managers.

 

For that you need to configure your flow designer like this-

please review the screenshot and apply the code

 

NawalSingh_0-1758709735108.png

here is the code- 

----------------------------------------------------------------------------------

var app= fd_data.trigger.current.u_project_manager; // change your field name
return "ApprovesRejectsAnyU["+app+"]";
 
-------------------------------------------------------------------------------------------------------

 

Please test and let me know.

 

If my response is helpful please accept as solution and marked as helpful for future readers.

 

Thank you!!

raviteja1600
Tera Expert

Hi @ammar_k 

 

1. Use “Ask for Approval” in a Subflow

Create a Subflow that handles approvals for each selected manager. This makes your logic reusable and modular.

2. Convert List Field to Array

If you're using a List Collector or a field that stores multiple users, convert it to an array using a “List Collector Convert to Array” action. This allows looping through each selected user.

3. Use “For Each” Logic

Inside the Flow Designer:

  • Add a “For Each” action to iterate over the array of selected managers.
  • Within the loop, use “Ask for Approval” for each user.

Advanced Scripted Approval Logic (Optional)

If you want to replicate group approval logic or handle primary/backup approvers, you can use Scripted Approvals:

var grps = fd_data.flow_var.approval_groups.split(',');
var rl = '';
for (var i = 0; i < grps.length; i++) {
  rl += (i === 0 ? '' : '&') + 'ApprovesAnyG[' + grps[i] + ']';
}
rl += 'OrRejectsAnyG[' + fd_data.flow_var.approval_groups + ']';
return rl;

This script builds a rule that:

  • Requires one approval per group
  • Rejects if any group member rejects.

 

If the above information is helpful to you, please mark it as helpful and accept the solution.

 

Regards,

Raviteja

Ankur Bawiskar
Tera Patron
Tera Patron

@ammar_k 

you can use Flow which triggers when state reaches

1) Then use Flow Variable of type String

2) then use "Set Flow Variables" flow logic to grab managers of all those users

3) then use Ask for Approval and set this flow variable

OR

You can use scripted approval, check this link

Scripted Approvals in Flow Designer with Flow Variables 

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

Nishant8
Giga Sage

Hello @ammar_k, if you have all the managers already available in a field then you can simply use that field in the 'ask for approval' rule, something like below:

Nishant8_0-1758714264499.png

 

Regards,

Nishant