Change request is rejected if one person rejects in a group

Roc
Kilo Explorer

HI

i am trying to modify my current workflow for a change request for a group (the group has 6 members) the approvals work as expected where at least 51% need to approve before the request moves forward. However if one person rejects the others can still approve and get to that 51% still progressing the change request. 

I want to be able to say that ANYONE that rejects from that group then the change is rejected and canceled. but continue to have the 51% rule in place in case no one rejects.

For example:

If a CHG is submitted and gets to CAB group to approve and 1 person approves then the second rejects the WF is still waiting for at least 51% to approve BUT it should reject the change and make all other no longer required. Can someone recommend a chnage to the current working workflow i have?

// 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 ...
// }
// 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 ...
// }
//Approve based on percentage from each group
var approvePercent = 51;
var approveCount = 0;
for(var id in groups){
var group = groups[id];
if((group.approved/group.total)*100 >= approvePercent){
//Mark the group approval record 'Approved'
var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.get(id);
groupApproval.approval = 'approved';
groupApproval.update();
approveCount++;
}
if((group.rejected/group.total)*100 > (100 - approvePercent)){
answer = 'rejected';
break;
}
}
//Ensure all groups have approved
if(approveCount == counts.total){
answer = 'approved';
}

Thanks you in adavance

Roc

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Change the reject loop to below script and see if it works

if(group.rejected > 0){
answer = 'rejected';
break;
}

 

View solution in original post

3 REPLIES 3

dvp
Mega Sage
Mega Sage

Change the reject loop to below script and see if it works

if(group.rejected > 0){
answer = 'rejected';
break;
}

 

Roc
Kilo Explorer

DVP

 

Thank you very much for that. It worked!! I appreciate your quick response!

Best Regards,

Roc

You are very welcome 🙂