- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 02:45 PM
Hello all,
I am running into a hard to explain issue where a string field I have is not sorting correctly. I am testing with just 2 different types of string values possible, and they are just randomly being displayed. The string values are filled via a calculated value which just pulls in the name field from a different field. Here is my simple testing script:
var glAggr = new GlideRecord('u_monitoring');
glAggr.addQuery('sys_created_on','>',gs.daysAgo(7));
glAggr.orderBy('u_service_name');
glAggr.query();
while(glAggr.next()){
gs.print(glAggr.u_service_name);
}
There are only 2 possible string values for u_service_name, yet they are randomly being displayed:
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: A Service
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: A Service
*** Script: B Service
*** Script: A Service
*** Script: A Service
*** Script: A Service
*** Script: A Service
*** Script: B Service
*** Script: B Service
*** Script: A Service
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: B Service
*** Script: A Service
*** Script: A Service
*** Script: A Service
*** Script: A Service
*** Script: B Service
Not sure how to explain this behavior. Anyone ran into something similar before?
Best regards,
Brian
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 02:50 PM
I may be wrong on this, but I believe this is the issue...
Calculated fields are calculated after the records are retrieved from the database, but sort order is applied during the DB query, so the calculated field won't be calculated yet, hence the order wouldn't apply.
You may have to apply your own sorting on that field after the GlideRecord results are in...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 02:50 PM
I may be wrong on this, but I believe this is the issue...
Calculated fields are calculated after the records are retrieved from the database, but sort order is applied during the DB query, so the calculated field won't be calculated yet, hence the order wouldn't apply.
You may have to apply your own sorting on that field after the GlideRecord results are in...