- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 07:41 AM
Hi All,
Is there any js-function to get the user list object by group-name or is there any script to get all users from a group?
example group name is: IS&T Senior Leadership Team
Thanks & Regards,
Kiran Pedduri
Solved! Go to Solution.
- 29,666 Views

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2017 08:15 AM
Hi Kiran,
Sorry, I had an error in the first one. I was pushing the sys_id of the membership record, not the users. I've corrected it.
Easy change... You can 'dot-walk' to get that. If you want the user_name field (labeled User ID, like chuck.tomasi) you can change the answer.push() line to this
answer.push(mem.user.name.toString()).
You want the email,answer.push(mem.user.email.toString());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2018 06:29 PM
The key to remember is that watch lists (list fields) are just a comma separated string of sys_ids.
The (untested) code would look something like this:
// Example input value from watch_list=sys_id1,sys_id2,sys_id3
var wList = current.getValue('watch_list');
var list = wList.split(',');
var fNameList = [];
for (var i = 0; i < list.length; i++) {
var usr = new GlideRecord('sys_user');
if (usr.get(list[i])) {
fNameList.push(usr.getValue('first_name'));
}
}
var allFirstNames = fNameList.join(',');
// End result example: Chuck,Brett,Sarah,Jonah,Allison
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2020 03:58 AM
Report Helpers global business rule (out of the box) contains a function called getGroupMembers that does exactly that.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 12:00 AM
To retrieve a list of users by group name, you typically need to use the APIs provided by the service you are using. In this case, since you mentioned "Service Now," you would likely need to use the ServiceNow API.
ServiceNow provides a REST API that you can use to retrieve information, including user data. You would need to authenticate with the API using appropriate credentials and then make a request to fetch users by group name.
Here's a general outline of the steps you might take:
1. **Authenticate**: Obtain the necessary credentials (such as an API token or username/password) to authenticate your requests to the ServiceNow API.
2. **Make API Request**: Use the appropriate API endpoint to query for users based on the group name. ServiceNow's API documentation should provide details on the endpoint you need to use and the parameters required.
3. **Process Response**: Handle the response from the API request in your JavaScript code. Typically, the response will be in JSON format, which you can parse to extract the user information.
Here's a basic example of how you might accomplish this using JavaScript and assuming you're making a GET request to the ServiceNow API:
```javascript
const groupName = "IS&T Senior Leadership Team";
const apiUrl = "https://your-instance.service-now.com/api/your-api-endpoint";
// Make sure to replace 'your-instance' and 'your-api-endpoint' with your actual ServiceNow instance and API endpoint
fetch(`${apiUrl}/users?group=${groupName}`, {
method: 'GET',
headers: {
'Authorization': 'Bearer your_access_token',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
// Process the response data containing the user list
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
```
Remember to replace `'your_access_token'` with the actual access token or authentication method required by the ServiceNow API.
Additionally, ensure that your ServiceNow instance allows access to user data via the API and that you have the necessary permissions to retrieve this information.