Checking number of users who approved on a group on workflow

josephd01
Mega Guru
Hello Guys,
 
I am having a bit of a headscratcher with a workflow approval condition. I only have 1 group approval on my workflow, and I want to make sure that the group approval goes forward after 5 users have approved. Below is the code that I am trying to use, however what happens on the flow is that even after everyone approving the flow does not go forward. I am not sure where the problem is on my code.
 
 
var answer = '';
var groupIdToCheck = 'b85d44954a3623120004689b2d5dd60a';

if (groups[groupIdToCheck].approved >= 5) {
    answer = 'approved';
} else if (groups[groupIdToCheck].rejected > 0) {
    answer = 'rejected';
}
6 REPLIES 6

Sumanth16
Kilo Patron

Hi @josephd01 ,

 

Please try below approach:

https://www.servicenow.com/community/itsm-forum/how-to-get-mandatory-approvals-from-two-people-in-a-...

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

josephd01
Mega Guru

Hi,

 

Thank you for responding. I had no issue when I did this for users alone. But I have a requirement that requires me to use group approval and not user. I was able to get this to work with user approvals. I am just battling to get the group user approvals to work. I double checked the sys_id of the group so my only conclusion is something in my code is not working correctly. 

sushantmalsure
Mega Sage
Mega Sage

Can you share the screenshot of the script where its written? and if there is missing part in script ? 

I am not able to understand groups[] declaration which is used in if condition.

Also if this is under approval script of group approval then why 'counts.approved >=5' is not used in IF condition ?

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi, Please see screenshot

 

josephd01_1-1710397915323.png

 

Please see group sys_is : 

 

josephd01_2-1710398006137.png

 

Please see the comment provided by ServiceNow in the script: 

 

// Set the variable 'answer' to '', 'approved' or 'rejected' to indicate the overall approval status for this approval.
//
// This script is responsible for setting the approval state for each group that is part of this approval activity before
// returning the overall approval state for all of the group(s).
//
// When called, the following variables are available to the script:
//
// Overall for all of the groups that are part of this approval activity:
// counts.total = total number of groups that are part of this approval
// counts.approved = # of groups that approved so far
// counts.rejected = # of groups that rejected so far
// counts.requested = # of groups that are pending approval
// counts.not_requested = # of groups that are not pending approval
// counts.not_required = # of groups that approval is not required
//
// And for each group:
// groups[group_id].total = total number of users that are part of this group's approval
// groups[group_id].approved = # of users that approved so far
// groups[group_id].rejected = # of users that rejected so far
// groups[group_id].requested = # of users that are pending approval
// groups[group_id].not_requested = # of users that are not pending approval
// groups[group_id].not_required = # of users that approval is not required
//
// groups[group_id].approvalIDs[state] = array of user ids that are at the specified approval state
//
// Note: Iterate the groups using:
// for (var id in groups) {
// var group = groups[id];
// ... group.total ...
//