Script Approval Rules in flow deisgner

Ashwin Perumal1
Tera Contributor

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.

2 REPLIES 2

_ukasz Rybicki
Giga Guru

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

  1. 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)

  2. 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).

  3. Wait

    • Flow Designer automatically pauses until the approval completes.

  4. 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)

  5. 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

  1. 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...)

  2. 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...)

  3. 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...)

  4. 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! 🎉

Ankur Bawiskar
Tera Patron
Tera Patron

@Ashwin Perumal1 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader