What is the default "ORDERBY" for GlideRecord?

Vinay Krishna1
Kilo Guru

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. 

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

Hi Vinay,

 

ServiceNow docs has answer to all our questions. Follow link for detailed explanation of sorting mechanism.

 

Thanks,

Jaspal Singh

View solution in original post

5 REPLIES 5

DirkRedeker
Mega Sage

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