The CreatorCon Call for Content is officially open! Get started here.

Table api sys_user is not returning all accounts or retuned wrong total account

Aakansha2
Kilo Contributor

Hello,

As we are calling Table API for fetching user data (sys_user). where in code i am taking total count of the user with X-Total-Count. And we are using this api https://your-instance.service-now.com/api/now/table/sys_user?sysparm_limit=10000&sysparm_offset=0 for pagination.

As one of our customer have 61189 users (this value is returned by X-Total-Count) but when they are calling this api

https://your_instance.service-now.com/api/now/v1/table/sys_user?sysparm_limit=10000&sysparm_offset=6...

it is returning only one user. it should return 15 accounts. Why this api is not returning all accounts or it is returning wrong total user count. Please help me with that.

 

14 REPLIES 14

Hello Ankur,

Thanks for the reply. I have added below script in business rule. And table is used in business rule is sys_user. 

Script is as follows -

(function executeRule(current, previous /*null when async*/) {

// Add your code here
if(gs.getUserName() == "aa_vaishali") {
var u = gs.getUserName();
var qc = current.addQuery("user_name","aa_vaishali");
gs.print("query restricted to user: " + u); }

})(current, previous);

 

but it is not reflecting in the API. I have run this sys_user api in postman.
I am not sure what I am doing wrong.

 

Thanks & Regards

Aakansha 

 

Hi Aakansha,

So this is query business rule on sys_user table; when the API is being hit with aa_vaishali user then it should return only 1 record from sys_user table which has user_name as aa_vaishali

Is this a valid scenario?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I am hitting this API -

https://my-instance.service-now.com/api/now/table/sys_user?sysparm_limit=20000&sysparm_offset=0&query=true

my query is ->

1. I have total user account 15899. so this API should return how much user??

2. Scenario is that I don't want user_name "aa_vaishali" in the response. but it is not working

Hi Aakansha,

you can have 2 approaches here:

1) make sure the query itself filters the records

https://my-instance.service-now.com/api/now/table/sys_user?sysparm_limit=20000&sysparm_offset=0&sysparm_query=user_name!=aa_vaishali

2) or query business rule should be updated as below; Ensure the query BR condition has this; if you are using rest.user as the user for authentication for the API then use this; give that user's username in the BR condition; so that BR runs only for this API user

gs.getUserName() == 'rest.user'

(function executeRule(current, previous /*null when async*/) {

current.addQuery("user_name","!","aa_vaishali");

})(current, previous);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have tried the both approaches but still can see expected user.

https://my-instance.service-now.com/api/now/table/sys_user?sysparm_limit=20000&sysparm_offset=0&query=user_name!=test_10