Want to skip approval if requested by is same as approver

Adi13
Tera Contributor

I have one group approval on RITM after request submit in that group there are two persons for approval 'A' and 'B' .My requirement is when the request is submitted by 'A' want to skip approval.

3 REPLIES 3

Aman Kumar S
Kilo Patron

You might wanna add If condition activity before your approval activity 

1. Check Advanced = True

2. Add script:

answer = ifScript();

function ifScript() {
var reqFor = current.variables.requested_for ; // replace with your value for requester for.
var approvalUser = new GlideRecord("sys_user_grmember"):
approvalUser.addQuery("group","sys_id of your Approval GROUP");
approvalUser.query();
while(approvalUser.next()){
if(approvalUser.getValue("user") == reqFor){
    return 'yes';
}
return 'no';
}

Let me know if this works, feel free to drop Thumbs up 🙂

Best Regards
Aman Kumar

Sagar Pagar
Tera Patron

You have to use the "Approval user" activity in workflow. Check the advance option to true and use the below script.

It will skip the approval for user A/ B, if he/she is request opened by user.

 

answer = [];

var approvers = new GlideRecord('sys_user_grmember');
approvers.addEncodedQuery('approval_group_sys_id');
approvers.query();
while(approvers.next()) {    
	if(approvers.user.toString() != current.request.opened_by.toString()) {
		answer.push(approvers.user.toString());
	}
}

 

Regards,

Sagar Pagar

The world works with ServiceNow

Manimegala1
Tera Contributor
Hi There,
Please find the below 2 scenarios.
 
Scenario 1: If opened_by user is one of the approver group member, then the entire approval should skip.
 
answer = ifScript();
 
function ifScript() {
var count = 0;
var grg = new GlideRecord('sys_user_grmember');
grg.addEncodedQuery('Group SysID');
grg.query();
while (grg.next()) {
if (grg.user.toString() == current.request.opened_by.toString()) {
count++;
}
}
if (count > 0) {
return 'yes';
} else {
return 'no';
}
}
 
 
Scenario 2: If opened_by user is one of the approver group member and the approval should not go to only one approver(Opened_by), but others should get approval request.
 
answer = [];
 
var approvers = new GlideRecord('sys_user_grmember');
approvers.addEncodedQuery('approval_group_sys_id');
approvers.query();
while(approvers.next()) {    
if(approvers.user.toString() != current.request.opened_by.toString()) {
answer.push(approvers.user.toString());
}
}
 
Please drop thumps up, if it helps you 🙂