Reputation: 31
https://MYINSTANCE.now.com/api/now/table/sys_user_grmember?sysparm_display_value=all
{
"result": [
{
"sys_id": {
"display_value": "0055d61edb7fbe00115032dd7c961914",
"value": "0055d61edb7fbe00115032dd7c961914"
},
"sys_updated_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"sys_created_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_mod_count": {
"display_value": "0",
"value": "0"
},
"sys_updated_on": {
"display_value": "09.07.2017 12:36:50",
"value": "2017-07-09 02:36:50"
},
"sys_tags": {
"display_value": "",
"value": ""
},
"user": {
"display_value": "Rahul Davis",
"link": "://MYINSTANCE.com/api/now/table/sys_user/cb154dd94f735e000d7f0ed11310c7a7",
"value": "cb154dd94f735e000d7f0ed11310c7a7"
},
"sys_created_by": {
"display_value": "SD1234",
"value": "SD1234"
},
"group": {
"display_value": "MAJOR_INCIDENT_MANAGEMENT_AU",
"link": "://MYINSTANCE.com/api/now/table/sys_user_group/2cc9e481db6b7200115032dd7c9619e3",
"value": "2cc9e481db6b7200115032dd7c9619e3"
}
}
]
}
and so on......
how can i get group name by giving username as rahul davis with sysparm with this API can anyone suggest me which one i have to use for this json format ??
Upvotes: 0
Views: 2298
Reputation: 601
First of all, you don't want to pull group membership based on a user's name, because name is not a unique value. Instead, if you can't get the user's sys_id, you might want to use their user ID. To do that, simply use a REST GET call on the following API:
https://[[INSTANCE]].service-now.com/api/now/table/sys_user_grmember?sysparm_query=user.user_name%3D[[USERNAME]]&sysparm_display_value=all
Simply replace [[INSTANCE]] with your instance name, and [[USERNAME]] with the username you're looking for. In this line above, you can see the segment in italic (sysparm_query=user.user_name%3D[[USERNAME]]) is the query. I got it, by navigating to sys_user_grmember.list from the application navigator, and running a query by dot-walking from the user field, to the user's used ID field in the query, and checking for a specific user ID.
Also, if you're looking for the group name, just append &sysparm_fields=group.name to your query URI.
You can use the "REST API Explorer" in ServiceNow to construct REST queries using the table, or other APIs, really easily in the future, if you ever need some quick help! :-)
Upvotes: 2