Send Approval Request to Users with Role

Luke10
Kilo Expert

Hello Everyone,

I'm new to ServiceNow scripting and need some help. I have a custom role for approval changes. Only users with the 'change_approver' role should be sent the request approval.

When I go to the 'Approval Request' notification and 'Who will receive tab' there is not option for 'roles'. So, I'm missing something.

Does anyone know what I need to do? Any help would be appreciated.

Thanks!find_real_file.png

1 ACCEPTED SOLUTION

Luke10
Kilo Expert

I solved the issue. Turns out the code is correct. The workflow activity is for Approval Group. So, it didn't even look for user roles. The activity should have been Approval User. That fixed it. Thanks for everyone's help and advice.

View solution in original post

15 REPLIES 15

Okay. This this may be what I'm looking for. I know that this was written in the workflow for approval notifications. I checked and that is the sys_id for 'change_approver'. Not sure why it isn't working, though.

var answer = [];
var groupMemberships = new GlideRecord('sys_user_grmember');
groupMemberships.addQuery('group', current.getValue('assigmnet_group'));
groupMemberships.query();
while(groupMemberships.next()) {
	var user_sys_id = groupMemberships.getValue('user');
	var hr = new GlideRecord('sys_user_has_role');
	hr.addQuery('user', user_sys_id);
	hr.addQuery('role', 'IN', '43f46433db8a6f409e9bf27139961947');//sys_id of role
	hr.query();
	if(hr.next())
    {
	  answer.push(hr.getValue('user'));
	}
}

Everything looks good. Except there is a typo in assignment_group field name

var answer = [];
var groupMemberships = new GlideRecord('sys_user_grmember');
groupMemberships.addQuery('group', current.getValue('assignment_group'));
groupMemberships.query();
while(groupMemberships.next()) {
	var user_sys_id = groupMemberships.getValue('user');
	var hr = new GlideRecord('sys_user_has_role');
	hr.addQuery('user', user_sys_id);
	hr.addQuery('role', 'IN', '43f46433db8a6f409e9bf27139961947');//sys_id of role
	hr.query();
	if(hr.next())
    {
	  answer.push(hr.getValue('user'));
	}
}

So, I fixed the typo, but users with the 'change_approver' role are still getting approval notifications. It is sending to everyone in the assignment group instead of just those with 'change_approver' role.

Is the group field on approval activity filled in ?

No. It's blank, but the user field has ${requested_by.manager}.

find_real_file.png