how to orderBy a field ,which a reference table's field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2022 11:55 PM
I want to query incident table,how to orderBy by reference table(user)'s field?
var gr = new GlideRecord('incident');
gr.orderBy('user.name');// user.name gr.query(); while(gr.next()){ gs.info(gr.number); }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 12:02 AM
Hi
Check the below link it have an answer for you
https://community.servicenow.com/community?id=community_question&sys_id=45375dcbdb174090d82ffb2439961917
Thanks
Chandu Telu
Please Mark ✅ Correct/helpful, if applicable,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 12:08 AM
Hello
I don't think so, orderby will work on dot walking fields. Below thread has mentioned workaround. Could you please check if it helps.
Regards,
Akshay

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 12:24 AM
Hi,
Yes, it is not possible to apply OrderBy on dodt walked fields in case of reference field. For reference fields default orderBy is applied on display value.
You are applying wrong query here, there is no field with name 'user' on incident table.
If you apply OrderBy on reference fields then it sort it based on display value of reference table. eg. If you apply OrderBy on caller_id then it sort it based on Name of Caller.
var gr = new GlideRecord('incident');
gr.orderBy('caller_id');// user.name is invalid
gr.query();
while(gr.next()){
gs.info(gr.number);
}
Thanks,
Anil Lande
Thanks
Anil Lande