- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 09:22 AM
I have 2 lists that will always mirror each other. One of the lists is the OOB approval table, the other is a Custom Approval Table I have made for a specific purpose.
I am trying to run a "Run Script" in the workflow that queries both tables for the current.request. I then am wanting to put both result sets in the same order. I have tried various ways and none work. Orderby, OrderByDesc and both together.
Has anyone else ever run into this problem. Keep in mind that this is in a "Run Script" in a workflow. Are there restrictions I am not aware of?
Here is a snippet:
//grabs approvers from oob approval list
function GetOOBApprovers(request)
{
var grOOBList = new GlideRecord('sysapproval_approver');
grOOBList.addQuery('sysapproval', request);
grOOBList.addQuery('state', 'requested');
grOOBList.orderBy('approver.name');
grOOBList.orderByDesc('sys_created_on');
grOOBList.query();
while(grOOBList.next())
{
gs.info('LOG: ' + grOOBList.approver.name);
}
}
//grabs approvers from custom approval list
function GetCustomApprovals(request)
{
var grCustomApproversList = new GlideRecord('u_zone_approvers_list');
grCustomApproversList.addQuery('u_request', request);
grCustomApproversList.orderBy('u_approver.name');
grCustomApproversList.orderByDesc('sys_created_on');
grCustomApproversList.query();
while(grCustomApproversList.next())
{
gs.info('LOG: ' + grCustomApproversList.u_approver.name);
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 09:58 AM
Can you tell us how are you confirming that records are not sorting by order?
I'm assuming that you checked in the Script log statements module and getting confused with the way the records are logged. If you look closely into the records in sys logs, the created time for all of them will have the same time.
If you would like to see the log statements in order then use an increment in loop and put it in log statement. Here is the updated script
var grOOBList = new GlideRecord('sysapproval_approver');
grOOBList.addQuery('sysapproval', request);
grOOBList.addQuery('state', 'requested');
grOOBList.orderBy('approver.name');
grOOBList.query();
var count = 0;
while(grOOBList.next())
{
++count;
gs.info('LOG: ' + count + ' ' + grOOBList.approver.name);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 10:12 AM
Yes it will order by the name of approver and it did.. I tested in developer instance and it is working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-15-2017 10:17 AM
I was depending on the logs too much. I was trusting the order I was seeing displayed in the logs, my mistake.
Thank you