Table api sys_user is not returning all accounts or retuned wrong total account
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2020 11:55 PM
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.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2020 11:48 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 12:03 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 01:25 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 02:08 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 05:49 AM
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