- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 01:53 AM
What is the api to get the user and group association ? ( i.e sys_user_has_role contains the association between user and roles similarly is there anything for group )
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 01:58 AM
@Adithya Khurana sys_user_grmember table gives you the user and group relationship.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 02:03 AM
Please try "sys_user_grmember";
API: /api/now/table/sys_user_grmember/{Sys_id}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 01:54 AM
Please take a look at the below example and make a function call with the required role and sys_user Column name.The function getUsersWithRole should return you all the users who have the required role.
//Call the below function with the ROLE and one of the columns on sys_user table. //The below function call returns all the userNames of the users who have the role "Test_Role" var users = getUsersWithRole("Test_Role","user_name"); gs.print(users); //Array of Users with required role function getUsersWithRole(role,user_column) { var users = []; var userRoleJson = makeAPICall("https://***.service-now.com/api/now/table/sys_user_has_role?role="+role); for(var i=0; i<userRoleJson.result.length ;i++) { var usersJson = makeAPICall(userRoleJson.result[i].user.link); users.push(usersJson.result[user_column]); } return users; } function makeAPICall(endPoint) { try { var rest = new sn_ws.RESTMessageV2(); rest.setEndpoint(endPoint); rest.setHttpMethod("get"); //This below user needs to have access to sys_user_role table and sys_user table rest.setBasicAuth("Test_User","Test_123"); var response = rest.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); if(httpStatus==200){ return JSON.parse(responseBody); } } catch(ex) { var message = ex.getMessage(); } }
Please mark it helpful if it helps..
Thanks,
Sonia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 02:02 AM
Thanks. I want to know the api / table name for user & groups association.
Eg: userx is associated with 3 groups, what is an api to get those associations ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 01:58 AM
@Adithya Khurana sys_user_grmember table gives you the user and group relationship.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 02:03 AM
Please try "sys_user_grmember";
API: /api/now/table/sys_user_grmember/{Sys_id}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.