Sort field by label and not by value

lee9
Kilo Contributor

Hi all, 

By default if you use "orderby" in a choice field the sort is done by the actual value of that choice field as defined in the choice table. There are times where the choice value is a numeric / integer but the actual choice Label is characters. Right now I have a requirement whereby I have to returned the results (from an external API) sorted by category however since category is a choice field the query is returning results that are sorted by the value of the category field. The desired behavior is to sort the query results based on the display value of the category field which is the Label field on the choice table. 

 Would you please advise if there is a way to use the display value of a choice field rather than the actual value of a choice field when sorting your query results using a choice field.

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Hello,

Why you don't use the sequence field in the option choices. Order it the way you want the result to return and then use ORDERBY=sequence in the query

find_real_file.png

If label is the absolute necessity then please checkout the below thread:-

https://community.servicenow.com/community?id=community_question&sys_id=e787b46fdb66049423f4a345ca9619fa

 

Please mark answer correct/helpful based on impact.

lee9
Kilo Contributor

Hi, I need it for an external API.

The solution that I am looking for is to change the logic of the sort field,

Thank you.