kristymerriam
Administrator

 

In this Did You Know episode, I take you on a quick journey into optimizing data sorting with the powerful "orderBy()" function in ServiceNow’s GlideRecord queries. For developers and admins tasked with organizing large data sets, understanding multi-field sorting can make all the difference.

 

Getting Started with "Order By" in ServiceNow

The"orderBy()" function allows developers to sort query results, typically in ascending order, making it easy to prioritize based on criteria like incident severity or project deadlines. The demo begins with creating a query to sort incidents by priority in ascending order, ensuring that critical tasks (priority 1) appear at the top.

 

Adding Depth with Multi-Field Sorting

When working with extensive records, sorting by one field may not be enough. I demonstrate adding an "orderByDesc()" clause, which allows sorting incidents by their creation date within each priority level, ensuring the latest incidents appear first within each priority grouping. This dual sorting approach is ideal for support teams, helping them keep an eye on both priority and recency.

 

Why Multi-Level Sorting Matters

Using multiple "orderBy()" clauses can help teams make sense of complex data, streamline reporting, and ensure that high-priority items remain front and center. By combining "orderBy()" with "orderByDesc()," I show how easy it is to create queries that display exactly what teams need to see, even in vast datasets.

 

Practical Applications

For anyone managing support queues, incident reporting, or large databases, this sorting method is a game-changer. Whether you’re building custom reports or managing daily workflows, multi-level sorting lets you customize data views to highlight what matters most.

 

Learn more tips by following our Did You Know series on the ServiceNow Developer Program. Try these sorting techniques in your ServiceNow instance and see how they streamline your data management!

1 Comment
Chuck Tomasi
Tera Patron

I love it. Thanks Kristy for another great video.

 

Did you know you can also do this from the list view as well using the "Add Sort" button? 

ChuckTomasi_0-1731106975450.png

To copy Kristy's example, sorting by Priority and Opened (descending), it would look like this.

ChuckTomasi_1-1731107213944.png

 

For those that want to get really geeky and want to modify the URL so you can make URLs specific to your sorts, check out how this is done in the sysparm_query parameter in the URL by use of the ORDER and ORDERDESC keywords. Just pay close attention to a) the URL encoding (e.g. %255E, %3D, and so on) and b) there is no equals sign (or encoded equivalent) between ORDERBY/ORDERBYDESC and the field name. For example:

https://your_instance.service-now.com/now/nav/ui/classic/params/target/incident_list.do%3Fsysparm_query%3DORDERBYpriority%255EORDERBYDESCopened_at%26sysparm_first_row%3D1%26sysparm_view%3D