The CreatorCon Call for Content is officially open! Get started here.

Auto approve if the user exists more than once in the workflow

Karthikpasikant
Tera Guru

Hello everyone!

 

We have several workflows with multiple approval levels. We are trying to work on a solution if a user exist in level 1 approval and level 2 approval then the level 2 should be auto approved and move the workflow to next stage. is there anyway to achieve this scenario? 

(The reason behind this is, if a user receives two approvals level1 and level2 he approves level1 approval and he forgets that he has another approval pending and now the workflow doesn't moves to next stage)

 

Thank you in advance.

Karthik

1 ACCEPTED SOLUTION

I don't have any code, I just tried to verify it with empty answer (answer = [];)

What I would do is:

1. Define sysIDs of approvers (separated by commas) in some system property so you don't need to touch the WF once it is set

2. Write the script something like this:

var answer = [];
var approvers = gs.getProperty('myPropertyWithSysIDsOfSecondApproval');
var firstApproversArr = approvers.split(',');
var currentID = current.getUniqueValue();
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', currentID);
approvalGR.addQuery('state', 'approved');
approvalGR.query();
while (approvalGR.next()) {
    for (var i = 0; i < firstApproversArr.length; i++) {
        if (approvalGR.getValue('approver') == firstApproversArr[i]) {
             return answer;
        }
    }
}
answer = firstApproversArr;

 I haven't tested it so it may need some tweaking

View solution in original post

5 REPLIES 5

Jan Cernocky
Tera Guru

Hi Karhik,

I just checked it and it seems it works well if the second approval is not defined statically but by a script. So you do not define any particular user or group, but tick the advanced button and write some script.

The logic there expects to get an array of approvers to generate approval for. 

So you need to write a script to query whether the first approval has been already approved by person A and if so, then return answer []

Otherwise use push.answer(user1), push.answer(user2), etc.

When I tested it and set script in Approval 2 as answer = [] as soon as I approved the first approval round, it skipped the second approval and went straight to the catalog task.

 

JanCernocky_0-1665520688353.png

 

Hi Jan,

 

Thank you for replying. I agree your idea of having script in 2nd level to generate approvals. Could you please share the code here if possible. I will give a try in our instance.

 

Thank you,

Karthik

I don't have any code, I just tried to verify it with empty answer (answer = [];)

What I would do is:

1. Define sysIDs of approvers (separated by commas) in some system property so you don't need to touch the WF once it is set

2. Write the script something like this:

var answer = [];
var approvers = gs.getProperty('myPropertyWithSysIDsOfSecondApproval');
var firstApproversArr = approvers.split(',');
var currentID = current.getUniqueValue();
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('sysapproval', currentID);
approvalGR.addQuery('state', 'approved');
approvalGR.query();
while (approvalGR.next()) {
    for (var i = 0; i < firstApproversArr.length; i++) {
        if (approvalGR.getValue('approver') == firstApproversArr[i]) {
             return answer;
        }
    }
}
answer = firstApproversArr;

 I haven't tested it so it may need some tweaking

Hi Jan,

Thank you so much for sharing Jan. I will definitely try it right away and also tweak it based on our variables and will update the post. 

Thank you,

Karthik