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

josephd01
Mega Guru

I used the following code on the forum (Solved: Custom condition is not working on group Approvals - ServiceNow Community) and that seems to work, however I would still feel more comfortable if the sys_id narrowed down the group. Still hoping someone can help.

 

for (var id in groups) {
var group = groups[id];
/*if(groups[id].approvalIDs['conditionally_approved'])
{
answer ='conditionally_approved';
}
else */

if(group.approved >= 5) {
answer ='approved';
}
else if(group.rejected > 0) {
answer ='rejected';
}
}

I have tried it this way and it fails. So, I am confused that is the group sys_id why is it not recognizing it as the group.

 

// Define the sys_id of the group you want to target
var targetGroupId = 'b85d44954a3623120004689b2d5dd60a';

// Loop through the groups
for (var id in groups) {
    // Check if the current id matches the target sys_id
    if (id === targetGroupId) {
        var group = groups[id];
        // Perform your checks or actions specific to the target group
        if (group.approved >= 5) {
            answer = 'approved';
        } else if (group.rejected > 0) {
            answer = 'rejected';
        }
   
    }
}