- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 07:31 AM
Hello all,
The script include should return group member or user with role, based on the condition. However, it isn't working. What might go wrong.
Thank you
var GetUsersUtils = Class.create();
GetUsersUtils.prototype = {
initialize: function() {},
GetListOfUsers: function(current) {
var users = [];
if (current.u_service_group == 'IT Services') {
var memObj = new GlideRecord('sys_user_grmember');
memObj.addQuery('group', '5c6dd3b98760a110bd37986adsdsdf'); //Group sys_id
memObj.query();
while (memObj.next()) {
users.push(memObj.getValue('user'));
}
} else {
var grUser = new GlideRecord('sys_user');
grUser.addEncodedQuery('active=true');
grUser.query();
while (grUser.next()) {
var grRole = new GlideRecord('sys_user_has_role');
grRole.addQuery("user", grUser.sys_id);
grRole.addEncodedQuery('role=c900c5e5fdgdfgdfge4a73a24ff6a746'); //role sys id
grRole.query();
while (grRole.next())
users.push(grUser.getValue('sys_id'));
}
}
return 'sys_idIN' + users.toString();
},
type: 'GetUsersUtils'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 08:08 AM
Hi @tsoct,
Add some gs.log inside the script include and check if while loop is adding sys_id of users and finally before return "is the users arraylist has some data or emtpy"
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 07:33 AM
Hi there,
This will help you solve your issue within minutes:
- 2020-10-21 - Blog - Q: Help!!! My code is not working! A: Did you debug your code?
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
03-15-2024 08:08 AM
Hi @tsoct,
Add some gs.log inside the script include and check if while loop is adding sys_id of users and finally before return "is the users arraylist has some data or emtpy"
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2024 08:16 AM
I did and found the issue. Thanks