
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 02:53 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:07 AM
You need to split these into 2 gliderecords. One with null and one without.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:12 AM
I was afraid so too.
You know of a way to combine those two gliderecords into one?
Michiel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:20 AM
Not that I am aware of at this moment. Let me try to dig a bit. Will try to update the thread back if I find something.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:21 AM
Well you can,
This could be a script include..
var arr=[];
var str= "Your query";
var tbl=new GlideRecord('table_name');
tbl.addEncodedQuery(str+'^field_name!=NULL');
tbl.orderBy('field name');
tbl.query();
while(tbl.next()){
arr.push(tbl.getValue('sys_id')); // to store the sys id of all the records which are not having the date field as empty
}
var nl=new GlideRecord('table_name');
nl.addEncodedQuery('field_name=NULL');
nl.query();
while(nl.next()){
arr.push(nl.getValue('sys_id')); // to store the sys id of all the records which are having the date field as empty
}
return arr;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:23 AM
Just thinking out loud, did you try to achieve that in the list view using filters...and try to use the query generated by system via EncodedQuery??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2017 05:25 AM
Hmm. Blank will come last if you sort Z-A?