- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2020 04:12 AM
Hi all,
What is the default order the system queries/displays records in GlideRecord API?
For example,
var gr=new GlideRecord('incident');
gr.query();
while(gr.next())
gs.print(gr.number);
The system displays all incident numbers, but in what order? It's not based on "sys_created_on", so I wonder what it is.
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2020 05:17 AM
Hi Vinay,
ServiceNow docs has answer to all our questions. Follow link for detailed explanation of sorting mechanism.
Thanks,
Jaspal Singh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2020 05:36 AM
Hi
I am not sure about what ServiceNow does, but I just know how database servers do behave.
1) when you just query the whole table without any condition, the order is. RANDOM. This just depends on how the database cached or stored the records physically in the table. Each new call may give you different orders in hat case.
2) if you filter, the DB Server tried to read data first by its clustered index, then by any index on fields you filter by
3) if vou put an order by, you make things clear.
I can imagine that ServiceNow behaves also that way, when doing a GlideRecord.
This may behave completely different for Lists, be careful.
Let me know if that answered your question and mark my answer as correct and helpful.
BR
Dirk