- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2019 01:52 PM
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!
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2019 11:16 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 07:19 AM
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'));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 07:28 AM
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'));
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 09:09 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 11:06 AM
Is the group field on approval activity filled in ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 11:24 AM