- 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 02:17 AM
Hello Ridhima,
I noticed that you have marked my comment as correct earlier, but now it is not. I have also provided a rejoinder with the corrected line of code.
Posting it here again for your reference.
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.getValue("user"));
}
Kindly check and mark it correct so that the question is moved to the solved list.
- 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 01:17 AM
Hi,
Just to inform the answer you marked correct will only push 1 user to the answer array
you need to use toString() to get all the users pushed into that array.
OR
use answer.push(userRole.getValue('user'));
I have shared the complete script with both the changes.
Please mark appropriate response as correct & helpful.
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 02:06 AM
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
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 02:08 AM
Hi there,
Did my answer help to resolve your question? Or do you still need some assistance on this? Let me know.
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