Need to create one check box and set approvals in change request through flow designer

suryaogeti1
Tera Contributor

Hi all,

I got one requirement from client, I have created one check box named 'custom', if it is checks true and save, it will go for the approval. the change request should be in new state, even if we keep it in other state other than new after the custom check box is true and saving, it should not allow and generate pop up like " we should move from new to assess "until it will approve after review. Anyone can approve from the team except the requestor, we need to exclude the requestor and after creating the change request in new state, we need to send a notification to the group as a reminder for approving the change, they will review, it's like a peer review.
I have tried it in my PDI, I am not able get the correct approach. Could you guys please help me with that


9 REPLIES 9

Hi @suryaogeti1 ,

1. I am sending a approval request to Assignment group on a change record on Update .
2. The Assignment Group has 5 members, and one of the members is the same user as the Requested By user.
3.Using the following approach, I am excluding the Requested By user from the Approval Team.
Approach:
1.Create a flow variable of type string

Rakesh_M_1-1779366760442.png

 


2.Add a Look Up Records action
Table - sys_user_grmember

Conditions -- Group is [Select the Group ]

                          User is not [Select the user you want exclude]
In My Case: 
Group is [Trigger - Record Updated➛Change Request Record➛Assignment group]

User is [Trigger - Record Updated➛Change Request Record➛Requested by]

 

Rakesh_M_0-1779363759543.png

3.Use flow logic -For Each and select previous records(look up records)

Rakesh_M_0-1779366679350.png


4.now inside For Each flow logic update flow variable using flow logic set flow variables with sys_ids of users.
Approval Team =[ (2 - For Each➛Group Member Record➛User➛Sys ID) , (Flow Variables➛approval Team) ]


5.Now use ask for approval action with Rules field using script.

var approvers = fd_data.flow_var.approval_team;
return "ApprovesRejectsAnyU["+approvers+"]";

 

Rakesh_M_2-1779367045108.png

6.Now here we excluded the requested for user from Approval.

for any changes in approval rules refer :Scripted Approvals in Flow Designer with Flow Variables 

 

Hi @suryaogeti1,

As @Rakesh_M  mentioned, you are very close, the issue is coming from mixing Approval Rule + Flow Designer approval, which causes unexpected behaviour like skipping or moving to cancel state.
-> Do not use Approval Rule in Change Request if you are already using Flow Designer. 

It conflicts with Flow approval and can result in:

  • No approver found
  • Flow going to fallback path (like Cancel/Reject)
If you found this useful, feel free to mark it as Helpful and accept it as the solution.
Regards,
VaniMadhuri

Ankur Bawiskar
Tera Patron

@suryaogeti1 

you can use scripted flow approval

Scripted Approvals in Flow Designer with Flow Variables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

it is not working

Tanushree Maiti
Tera Patron

Hi @suryaogeti1 

 

Try with this:

 

1 Use a Before Business Rule to enforce that the Change Request remains in the "New" state until approved, and to block state changes if the custom checkbox is checked. 

  • Table: Change Request [change_request]
  • When: Before (Insert/Update)
  • Condition: u_custom (your checkbox) is true AND State changes AND State is NOT New

 

(function executeRule(current, previous /*null when async*/) {

    if (current.state != 1) { // 1 represents the 'New' State

        gs.addErrorMessage('You must move the Change Request from New to Assess until it is approved after review.');

        current.setAbortAction(true);

    }

})(current, previous);

 

  1. In your peer review Flow Designer or Workflow, dynamically exclude the user who raised the Change from the group approval list. 
  • Use the Look Up Records action to query all members in the assignment/review group.
  • Add a Run Script action to iterate through the group members and filter out the Requestor (e.g., u_requested_by or opened_by).
  • Pass the resulting filtered array of users into the Ask for Approval action. 

 

Sample script for Flow: 

(function execute(inputs, outputs) {

    var filteredList = [];

    var requestor = inputs.u_requested_by; // Replace with your requestor field

    var members = inputs.group_members;

 

    while (members.next()) {

        if (members.user.toString() !== requestor) {

            filteredList.push(members.user.toString());

        }

    }

    outputs.approver_list = filteredList.join(',');

})(inputs, outputs);

 

  1. Peer Review Notification
  • Navigate to System Notification > Email > Notifications -New.
  • triggers when a Change Request is inserted or when the State is "New" and your custom checkbox is true.
  • Under the Who to send tab, select your chosen Peer Review Group.
  • Compose the message to include instructions regarding the peer review, embedding a direct link using ${URI_REF} for easy access to the record

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti