Within the REST API, can I use OrderBy with two variables

cburkins
Tera Contributor

When calling the inbound REST API (for tables), I'm a big fan of using the ORDERBY clause within the sysparm_query string.   Is it possible to use ORDERBY with two fields, rather than just one.   For example, first I want to sort by field1, then within those results, I'd like to sort by field2.     This assumes that within field1, there are duplicates.

1 ACCEPTED SOLUTION

henry_cheng
ServiceNow Employee
ServiceNow Employee

Hi Chad,



I tested on my OOB instance and it seems multiple ORDERBY or ORDERBYDESC can be used together.


You can have a try by below REST API, it should be working fine.


https://<instance-name>.service-now.com/api/now/v1/table/incident?sysparm_query=active=true^ORDERBYp...



Cheers


Henry


View solution in original post

2 REPLIES 2

henry_cheng
ServiceNow Employee
ServiceNow Employee

Hi Chad,



I tested on my OOB instance and it seems multiple ORDERBY or ORDERBYDESC can be used together.


You can have a try by below REST API, it should be working fine.


https://<instance-name>.service-now.com/api/now/v1/table/incident?sysparm_query=active=true^ORDERBYp...



Cheers


Henry


Wow, you're totally right.   Works great for me, thanks !