sorting script not working for 2 columns

MaharshiC
Tera Contributor

Hi,

 

I have created a relationship for my workspace and I want the values to get sorted in ascending order of 2 columns - segment_id and rail_route_unique_id but the script is only working for one column at once and not both columns together. Is there any other way to write the columns so both of them work together?

(function refineQuery(current, parent) {

	// Add your code here, such as current.addQuery(field, value);
current.addQuery('rail_request_number', parent.sys_id);
current.orderBy('segment_id');
current.orderBy('route_unique_id');

})(current, parent);

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

you can orderBy only 1 field and not more than 1 using current object, this is supported in GlideRecord query though

This you can verify when you visit any table list

If you order by Created then you cannot order on another field

This is platform behavior.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

You are using the correct syntax/convention per SN documentation

https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/... 

 

Maybe this is a workspace limitation?  Does the sort work by each column when only one is listed, or listed first?  If not, there is an issue with one of the column names or it just can't be sorted by that column.

Ankur Bawiskar
Tera Patron
Tera Patron

@MaharshiC 

you can orderBy only 1 field and not more than 1 using current object, this is supported in GlideRecord query though

This you can verify when you visit any table list

If you order by Created then you cannot order on another field

This is platform behavior.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader