How to bypass approval is requester is a member of approval Assignment Group

bostonsnow
Kilo Guru

Hello,

I am trying to figure out how to bypass the approval step in a catalog item workflow if the requester is part of the approval group. I pulled the code from the following community post:

https://community.servicenow.com/community?id=community_question&sys_id=98a5ef71dbce53045322f4621f96... 

Here is what I have:

-------------------------------------------------------

var ourUser = gs.getUser().getUserByID(current.requester);//current.requester - end user in RITM

answer = ifScript();

function ifScript()
{
if(ourUser.isMemberOf(sys-id-of-my-group))
{
return 'yes';
}
return 'no';
}

-------------------------------------------------------

This is not working for me as the workflow is not advancing to the workflow step after a Yes result. 

Any ideas? I feel like this should be easier than it is so I'm assuming I'm doing this wrong.

Thanks!

Mike

 

 

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

try adding if condition before approval activity

var person = current.request.requested_for;
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'sys-id-of-my-group');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
	answer = 'yes';
}else{
	answer = 'no';
}

View solution in original post

5 REPLIES 5

Mike Patel
Tera Sage

try adding if condition before approval activity

var person = current.request.requested_for;
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', 'sys-id-of-my-group');
ir.addQuery('user', person);
ir.query();
if(ir.next()){
	answer = 'yes';
}else{
	answer = 'no';
}

bostonsnow
Kilo Guru

Hi Mike!

 

Thanks for the quick reply! I tried this and it didn't work but I think I figured it out.

I changed:

var person = current.request_requested_for;

To:

var person = current.request.requested_for;

And it worked! Thanks so much!

Mike

 

 

Yes, I meant to add . and added _ by mistake. Thanks

Are still able to edit that post? If you can fix the typo I can set it to "Mark as Correct Answer". Thanks again!