Ordering GlideRecord with null values

Michiel Meijler
Tera Contributor

Hi,

I need to order a list of tasks on a date field in Ascending order.

By using the orderBy('date_field') the the tasks without a value for the date_field, will be ordered on top. I want to have these tasks at the end of my resultset.

Anyone for a solution?

Michiel Meijler

ServiceNow Developing Consultant
Odysseus Group

1 ACCEPTED SOLUTION

You need to split these into 2 gliderecords. One with null and one without.


View solution in original post

12 REPLIES 12

Sharique Azim
Mega Sage

Hi Michiel,



As you are mentioning you can get the records of those records with no date value at the top using .orderBy('field');   , can you try using .orderByDesc('field name'.




Read GlideRecord - ServiceNow Wiki   for more info.


Hi Sharique,



Thanks but ordering descending does not help. The records with null values will show at the end, but the other records are ordered incorrectly in that case.


What I need is a way to order first on valid dates in ascending order, then the records with null valued dates.



Regards,


Michiel


You need to split these into 2 gliderecords. One with null and one without.


Exactly kalaiarasam,, i was about to type the same.