We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to order GlideRecord query output vy datetime field

Milan13
Giga Expert

Hello,

I have a problem to sort output of a GlideRecord query by datetime field (Date/Time field).

Even if I convert the date/time field to number value, the orderBy function does not work, any idea why?

Appreciate your help,

Milan

var rec = new GlideRecord('sc_request');
rec.orderBy("u_date_from.getGlideObject().getNumericValue()");
rec.query();
while(rec.next()) {
gs.print(rec.number + ' - ' + rec.u_date_from); }

 

1 ACCEPTED SOLUTION

Oh Great that things got working & you got to know the issue. Kindly close the thread by marking appropriate answer as correct.

View solution in original post

8 REPLIES 8

Hi Milan,

if that is date/time then it should work as expected

is it not working as expected currently?

Regards
Ankur

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

It probably is - there seems to be a data quality issue which confused me a bit...tanks a lot.

Oh Great that things got working & you got to know the issue. Kindly close the thread by marking appropriate answer as correct.

I am glad to hear your goal has been achieved.

Saying this, I will appreciate if you close this thread, as answered.

Have a great rest of the day.

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