Approval Group : Approval showing No Longer required

ndp
Kilo Explorer

I have workflow activity Approval - Group , in which I have added 17 Groups for approval.

I have Condtion based on Script for approval in which I have written below code.

var approvalPercent = 50;
var approvalCount = 0;
for(var id in groups){
var group = groups[id];

if((group.approved/group.total)*100 >= approvalPercent){

var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.get(id);
groupApproval.approval = 'approved';
groupApproval.update();
approvalCount++;

}
if((group.rejected/group.total)*100 > (100 - approvalPercent)){
answer = 'rejected';
break;
}
}
//Ensure all groups have approved
if((approvalCount/counts.total)*100 >= approvePercent){
answer = 'approved';
}

When this workflow activity runs, approval getting send to all members included in 17 approval group.

But when I approve 2 groups I get "No Longer required" for all other groups but it should be in requested state...

I have checked System logs and I am not getting any error....but I can see "Engine" generated message as "After running a sequence of activities we expected a 'last executing' record to predict the future stages from"

So did something from SNOW OOB making approval as "No Longer required"?

3 REPLIES 3

seanphelan
Tera Expert

I think the group approval table entry is a behind the scene logic so you can identify groups which en-turn identifies the people who need to approve.  Servicenow approval workflow activity might be moving the item along and thus voiding your other approvals

Also, is your logic I do not understand the for loop with the update action.  Each time you you do an approval or rejection it is runing this logic so see what todo.  So, after the first vote, the async job runs

 

Servicenow will handle the updating of the approval requests on activity completion so after each vote you just need to run the query to get the run down of approved vs rejected vs total and for that I would so a GlideAggregate query counted by the approval status field

https://docs.servicenow.com/bundle/jakarta-application-development/page/script/glide-server-apis/concept/c_GlideAggregate.html

 

 

Santosh_Ksagar
Mega Sage
Mega Sage

the above script will check if 50% of each group members have approved or not? if approved then for rest of the member it will show no longer required.

Inactive_Use433
Mega Contributor

Hi Nirav,

Its been a long time you posted this question but I got the same requirement. I got the few reference from your code snippet.

posting my code snippet here 

var approvePercent = 50;
var approveCount = 0;
for(var id in groups){
var group = groups[id];
if((group.approved/group.total)*100 >= approvePercent){

var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.get(id);
groupApproval.approval = 'approved';
groupApproval.update();
approveCount++;
answer = 'approved';
}


if((group.rejected/group.total)*100 > (100 - approvePercent)){
answer = 'rejected';
break;
}
}

Thanks