How can I remove the first approver from the list of approvers on a second approval from the same group

kent_harwell
Giga Contributor

I have a workflow which has 2 user approval activities (First Approval and Second Approval), both approval activities are assigned to the same group. I would like to make sure the first approver is removed form the list of approvers for the Second Approval activity.

Although the same group will provide first and second approvals, it shouldn't be approved by the same person twice.

Can anyone help with how I can script this in the workflow?

find_real_file.png

5 REPLIES 5

Martin Rudack
Mega Sage

Check the "Advanced" checkbox on the second Approval Activity and set the approver by script. 

Get every user of the group except the user who approved the first approval. 

So I have created the following script to accomplish this, which worked for a while and then started adding the previous approver.

 

// Get the last approver for this record
var last_approver = '';
var appRec = new GlideRecord('sysapproval_approver');

appRec.addQuery('state', 'approved');
appRec.addQuery('document_id',current.sys_id);
appRec.orderBy('updated');
appRec.query();

while (appRec.next()) {
last_approver = appRec.approver.toString();
}


// loop through group members and add to array if not last approver
var answer = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "583be867db42bf40e14ad92b5e96195f"); // sys_id of group "Template Releasers BMO & BOA"
gr.query();
while (gr.next()) {
var gr_user = gr.user.toString();
if (gr_user != last_approver) {
answer.push(gr.getValue('user'));
}
}

 

Any Idea what I'm doing wrong?

kent_harwell
Giga Contributor

So I have created the following script to accomplish this, which worked for a while and then started adding the previous approver.

 

// Get the last approver for this record
var last_approver = '';
var appRec = new GlideRecord('sysapproval_approver');

appRec.addQuery('state', 'approved');
appRec.addQuery('document_id',current.sys_id);
appRec.orderBy('updated');
appRec.query();

while (appRec.next()) {
last_approver = appRec.approver.toString();
}


// loop through group members and add to array if not last approver
var answer = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "583be867db42bf40e14ad92b5e96195f"); // sys_id of group "Template Releasers BMO & BOA"
gr.query();
while (gr.next()) {
var gr_user = gr.user.toString();
if (gr_user != last_approver) {
answer.push(gr.getValue('user'));
}
}

 

Any Idea what I'm doing wrong?

kent_harwell
Giga Contributor

So I have created the following script to accomplish this, which worked for a while and then started adding the previous approver.

 

// Get the last approver for this record
var last_approver = '';
var appRec = new GlideRecord('sysapproval_approver');

appRec.addQuery('state', 'approved');
appRec.addQuery('document_id',current.sys_id);
appRec.orderBy('updated');
appRec.query();

while (appRec.next()) {
last_approver = appRec.approver.toString();
}


// loop through group members and add to array if not last approver
var answer = [];
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", "583be867db42bf40e14ad92b5e96195f"); // sys_id of group "Template Releasers BMO & BOA"
gr.query();
while (gr.next()) {
var gr_user = gr.user.toString();
if (gr_user != last_approver) {
answer.push(gr.getValue('user'));
}
}

 

Any Idea what I'm doing wrong?