Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Has anyone dot walked within an OrderBy command?

Chad27
Tera Expert

Hello,

I am trying to order by a field on a record I'm referencing within a function. The field cmdb_ci_service is a reference field on the task_cmdb_ci_service table but I want to order by a field that is on the cmdb_ci_service record. Has anyone successfully done this? Doesn't seem to be working for me. Below is a code snippet from my script. This works if I want to order by the cmdb_ci_service but won't work when dot walking and trying to order by to the u_business_service_tier. 

 

insertBS();

function insertBS() {
var ubus = new GlideRecord('task_cmdb_ci_service');
ubus.addQuery('task', current.sys_id);
ubus.orderBy('cmdb_ci_service.u_business_service_tier');
ubus.query();

 

Any suggestions? 

Thanks in advance.

1 ACCEPTED SOLUTION

Yea, not sure bud. I'm still looking around to see and I can sort of get why...but yea...seems unfortunate. The only thing I can think of as a sort of "band-aid" fix...is to create a similar field on your table (so now not dot-walking) and use an onAfter BR on the other table to copy the value in to your table's new field. Just to be able to sortBy it...tedious I know, but that's an option.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

8 REPLIES 8

vkachineni
Kilo Sage

What kind of field is u_business_service_tier?

 

The following works on incident

 

var ubus = new GlideRecord('incident');
ubus.orderBy('caller_id.company.name');
ubus.query();
while(ubus.next())
{
gs.info(ubus.caller_id.company.name + "****" + ubus.number );
}

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

u_business_service_tier is just a string field (drop down) with 4 choices. (tier_a, tier_b, tier_c, tier_d). 

Try with an encoded query

 

var ubus = new GlideRecord('incident');
ubus.addEncodedQuery('ORDERBYcaller_id.time_zone');
ubus.query();
while(ubus.next())
{
gs.info(ubus.number + " ** " + ubus.caller_id.name + " ** " + ubus.caller_id.time_zone);
}

Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

Unfortunately I received the same results using the encoded query. Seems like there has to be a way to do this, straightforward situation.