Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Auto Approve if the opened by is a member of a group?

praveenKumar2
Kilo Expert

I am looking for a way to auto approve a request if the opened by is a member of a group? Can someone help me how to code it!!!

Thanks.

pK

12 REPLIES 12

Valentina6
Giga Guru

Hi,


it can be done in the workflow, before to launch the approval, use a if action to check if the opened by is member of that group.



if(current.opened_by.isMemberOf('groupname')){


answer = true;


}


else


{


answer = false;


}



Hope it helps!



Regards,


Valentina


Sharique Azim
Mega Sage

You can use a run script to do the following:



var usr=   new GlideRecord(sys_user_grmember'');


usr.addQuery('user','current.opened_by);


usr.addQuery('group','current.assignment_group);


usr.query();


if(usr.next()){



var app= new GlideRecord(sysapproval_approver'');


app.addQuery('sysapproval','current.sys_id);


app.query();


while(app.next()){


app.state='approved';
app.update();


}}


Valentina6
Giga Guru

Instead if you need to check if the opened by person is member of any group use the following script:



var user = new GlideRecord('sys_user_grmember');


user.addQuery('user', current.opened_by);


user.query();



if(user.hasNext()){


answer = true;


}


else


{


answer = false;


}



Regards,


Valentina


praveenKumar2
Kilo Expert

I guess my question was wrong, This is the approval that needs to be skipped in case the defined approver is a member of the group.



find_real_file.png