Default sorting for Gliderecord output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 01:21 PM
We have the below code in our Business Rule to set the 'assigned to' field :
current.assigned_to = "";
var getgrpUsers = new GlideRecord('sys_user_grmember');
getgrpUsers.addQuery('group',current.assignment_group);
getgrpUsers.addQuery('user.title','CONTAINS','abc');
getgrpUsers.query();
if(getgrpUsers.next())
{
current.assigned_to = getgrpUsers.user;
}
How will the user records be sorted by default if multiple users contain 'abc' in the user tile field?
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 01:23 PM
you can add getgrpUsers.orderBy('user.title'); right before getgrpUsers.query();
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_ScopedGlideRecordOrderBy_String
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 01:27 PM
Thankyou ! This works.
However, if we need to debug the current script, is there any default sorting that the output records would follow?
We really need to figure out how the current code is setting the assigned to values before we modify the script with 'OrderBy' .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 01:24 PM
you need to user orderBy in your gliderecord query to sort records.
modify your code like below
current.assigned_to = "";
var getgrpUsers = new GlideRecord('sys_user_grmember');
getgrpUsers.addQuery('group',current.assignment_group);
getgrpUsers.addQuery('user.title','CONTAINS','abc');
getgrpUsers.orderBy('user.title');
getgrpUsers.query();
if(getgrpUsers.next())
{
current.assigned_to = getgrpUsers.user;
}
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2019 01:28 PM
Thankyou ! This works.
However, if we need to debug the current script, is there any default sorting that the output records would follow?
We really need to figure out how the current code is setting the assigned to values before we modify the script with 'OrderBy' .