Script Approval Rules in flow deisgner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 03:20 AM
Hello All,
I have a requirement to trigger user and group approvals parallely for a server catalog item where user can select multiple servers from list collector variable. If a server has managedby value then trigger aprpoval to managedby field or else trigger to managedby group for that server. I am able to trigger approvals parallely using do the following in parallel by getting values of managedby and managed by group and use two ask for approval in do the following in parallel.
The flow will wait until all users approve in user approval and for group approvals each person from a group should approve. I am able to achieve this using following approval Rule script syntax. If any one of the approvals is rejected, I wanted to make the ritm closed incomplete. Can anyone help me in approval script syntax for rejection scenario where any approval gets rejected the ritm should be closed incomplete and other approvals no longer required.
Note: Here the user approval and group approval are dynamic so we can't use OOB approval rules in ask for approval action.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 03:32 AM
Name of Problem
Parallel dynamic user/group approvals with rejection handling
General Proposal Solution
Use a single Ask for Approval action in Flow Designer with a scripted rule that combines all managed_by users (ApprovesAllU[...]) and all managed_by_group groups (RejectsAnyG[...]). Flow Designer will then wait for either all users to approve or any group member to reject. After completion, perform a Lookup Records on sysapproval_approver for any state=rejected. If found, Update Record on the RITM (sc_req_item) to closed_incomplete and Terminate Flow. No custom tables or external tools required—just two script snippets and standard actions 😊
Detailed Step-by-Step Solution
Build Approver Lists (Script Step)
Table: sc_req_item (RITM) → list collector variable servers
Script:
// Collect user and group sys_ids var userIds = []; var groupIds = []; servers.forEach(function(s) { if (s.managed_by) userIds.push(s.managed_by); else groupIds.push(s.managed_by_group); }); // Expose to Flow variables flowInputs.userIds = userIds; flowInputs.groupIds = groupIds;
(“One person from each group should Approve in Flow Designer”, SN Community) (ServiceNow)
Ask for Approval
Action: Ask for Approval
Approval rule (Scripted Approvals field):
return 'ApprovesAllU[' + userIds.join(',') + ']OrRejectsAnyG[' + groupIds.join(',') + ']';
This ensures all users must approve or any group member can reject (ServiceNow).
Wait
Flow Designer automatically pauses until the approval completes.
Lookup Rejections
Action: Lookup Records
Table: sysapproval_approver
Conditions: document_id=approval.sys_id^state=rejected
(“How do you determine who approved or rejected a Flow Designer approval”, SN Community) (ServiceNow)
Handle Outcome (If…Else)
If lookupRecords.count > 0 Then // Rejection occurred Update Record(sc_req_item): state = closed_incomplete Terminate Flow Else // All approved Continue End If
Simple If-Else, no extra functions.
Example Solution
An admin configures a Server Catalog flow: they collect each server’s managed_by or managed_by_group, then in one Ask for Approval action use the script above. If any group member rejects, the flow finds that rejection in sysapproval_approver, updates the RITM (sc_req_item) to Closed Incomplete, and halts further tasks—ensuring clean closure across dynamic parallel approvals 🙌.
Sources
One person from each group should Approve in Flow Designer, ServiceNow Community – shows scripted rules with flow variables (https://www.servicenow.com/community/developer-forum/one-person-from-each-group-should-approve-in-fl...)
Ask for Approval action designer, ServiceNow Docs – details scripted approval syntax (https://www.servicenow.com/docs/bundle/vancouver-build-workflows/page/administer/flow-designer/refer...)
Flow Designer 'Ask For Approval' action script requires multiple, ServiceNow Community – demonstrates scripting encoded approvals (https://www.servicenow.com/community/now-platform-forum/flow-designer-ask-for-approval-action-script...)
How do you determine who approved or rejected a Flow Designer approval, ServiceNow Community – use sysapproval_approver lookup (https://www.servicenow.com/community/now-platform-forum/how-do-you-determine-who-approved-or-rejecte...)
Please mark this as the accepted answer if it solves your requirement! 🎉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2025 03:34 AM
this link has approach for scripted approval
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader