Default sorting for Gliderecord output

Vibhuti4
Tera Contributor

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?

5 REPLIES 5

Mike Patel
Tera Sage

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

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' .

sachin_namjoshi
Kilo Patron
Kilo Patron

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

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' .