Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Distinct on REST API Results

Thomas Shelton1
Kilo Explorer

I am using the native REST API Explorer to fetch a list of users who have a specific role granted to them by being a group member. In the sys_user_has_role table a user could appear multiple times if they have multiple groups which duplicates the role in question. Short of changing roles in groups, is there a way to have the API response show only a distinct list of records? 

1 REPLY 1

Kieran Anson
Kilo Patron

Hi Thomas,

Your user records have a "roles" field so rather than querying the sys_user_has_role table, you can query the sys_user table directly such as:

GET https://dev52040.service-now.com/api/now/table/sys_user?sysparm_query=roles%3Ditil&sysparm_fields=user_name%2Cname&sysparm_limit=10

find_real_file.png