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.

Business Rule for Checking Requester Role and Add them into Group

butterDream16
Tera Contributor

Hi all,

 

I am totally new to ServiceNow administration and I bump into a request that I need some help here.

The requirement is as per below:

1. whenever there is a new policy exception created, check if the requester have sn_grc.business_user role.

2. if yes, then do nothing.

3. if no, then add the 'GRC Business User' group to the user.

 

I tried various script and it still does not work and hoping to get some guidance here.

 

Appreciate the advice/guidance from this community.

 

Thank you!

1 REPLY 1

Harish KM
Kilo Patron
Kilo Patron

Hi @butterDream16 try the below script. Assuming you script is on RITM table

 

var requestedForSysID = current.request.requested_for; // get requestedfor sysid


var userObject = gs.getUser().getUserByID(requestedForSysID);
if (userObject.hasRole('n_grc.business_user')) { // check user has role
return 'yes';
}
else{ // add user to group
var grp = new GlideRecord('sys_user_grmember');

grp.initialize();

grp.user = requestedForSysID;

grp.group= 'sysID of grp';

grp.insert();

}

Regards
Harish