- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 12:54 AM
Hi,
I want the users with specific role to approve a request, My workflow is working fine but the Approval user script is not working, Please help me with the same. Below is my script mentioned:
var answer = [];
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('role', 'x_adsr_recruit.hiring_manager');
userRole.query();
while(userRole.next()){
answer.push(userRole.user.sys_id);
}
Thanks
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 01:14 AM
Hi,
updated script should work fine now
please use this
see the changes in bold
1) use role.name to query with role name
2) use toString() while pushing user to answer array
var answer = [];
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('role.name', 'x_adsr_recruit.hiring_manager');
userRole.query();
while(userRole.next()){
answer.push(userRole.user.toString());
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 12:56 AM
Hi there,
The role field on sys_user_has_role, is a reference. So a sys_id. You are quering now on text. Just update that in your query and your fine, for example using role.name to query on or the sys_id instead of the role name.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 12:57 AM
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 01:03 AM
Try like this.
var answer = [];
var userRole = new GlideRecord('sys_user_has_role');
userRole.addQuery('role.name', 'x_adsr_recruit.hiring_manager');
userRole.query();
while(userRole.next()){
answer.push(userRole.user);
}
Mark the comment as a correct answer if this has solved the problem.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2020 01:29 AM
hi,
What Ankur mentioned is correct. If there are multiple users, just change this 1 line in my code.
answer.push(userRole.user);
TO
answer.push(userRole.getValue("user"));