Need help in querying users in alphabetical order

shreyas099
Kilo Explorer

Hi,

I am running a background script that queries all users & checks for duplicate notifications. I got the script all running, but when I run the script, I get an error as follows:

Large Table: Table handling an extremely large result set: 71441

  Query that got us here is: TABLENAME = sys_user

Now, I need help in a script that I can use to query all the active users according to alphabetical order, so that I can run the script in batches.

Please respond ASAP.

Regards,

Shreyas Pattabhi

3 REPLIES 3

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're using a gliderecord query you can use both gr.orderBy() and gr.setLimit().



GlideRecord - ServiceNow Wiki


Thanks Brad,



I tried for the same, but did not get much of a result. To be more precise, i'm looking at picking up users from a particular alphabet to another... for example say A-G. Can you please guide me in this regard?



var gnew = new GlideRecord('sys_user');


gnew.addActivequery();


gnew.orderBy('name');


gr.setLimit(1000);


gnew.query();



This is the code i"m using now.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Shreyas,



Just to add, you can use the combination of addQuery and setLimit to fetch few records as per the logic and update them in batch.