Sort field by label and not by value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2022 11:27 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 12:47 AM
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
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 02:58 AM
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.