API to get all the groups using the user_name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:02 AM
Hi Team,
I require a generic REST API, which when used should provide me with all the groups when I pass the user_id.
How can I achieve that?
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:21 AM
Without going into specific details - my approach would be:
1. Create script include for the API functionality. (query sys_user_grmember table). Here I would implement functionality of retrieving group data.
Example for group names would be:
getUserGroupNames: function(userId){
var response = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.query();
while(gr.next()){
response.push(gr.getDiplayValue('group'));
}
return response;
}
2. Create scripted REST API where you call script include for each endpoint. : https://docs.servicenow.com/bundle/kingston-application-development/page/integrate/custom-web-servic...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2018 04:48 AM
this should give the group list you are looking for
GET https://servicenowinstance/api/now/table/sys_user_grmember?sysparm_query=user.user_name%3DUserid