How to order catalog variable by sequence in with Lookup Select Box type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Has anyone found a solution to order a custom variable by sequence on a catalog item using a Lookup Select Box type? Using a reference qualifier with the ORDERBY keyword does not work for custom fields (which I have confirmed is expected behavior through a serivcenow support case). I have researched extensively and have found others have had the same issue. I figured it is worth the shot to ask the question again to see if any other bright minds have figured out a workaround for this problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
56m ago
A known error article (KB0695435) confirming that dependent Lookup Select Box variables don't honor ORDERBY in the reference qualifier on Service Portal. And as you've found, for Lookup Select Box variables, choices are sorted by label in alphabetical order, and there's no native configuration to change it.
That said, here are the workarounds the community has landed on, ranging from quick-and-dirty to more robust:
1. GlideAjax + Catalog Client Script (most reliable workaround)
One approach uses a client-callable Script Include that queries the sys_choice table with orderBy('sequence') and returns the options as JSON, then an onLoad Catalog Client Script calls it via GlideAjax and rebuilds the dropdown using g_form.addOption(). The idea is you clear the natively-rendered options on load and re-add them in sequence order. This works on both the platform UI and Service Portal but does introduce a brief flicker as the options get rebuilt.
2. Prefix the label with the sequence number
A simpler hack is to make the order part of the label itself by setting the Lookup label field to something like u_order,u_application_name. Since labels sort alphabetically, a numeric prefix (01, 02, 03…) forces the correct order. It's ugly but requires zero scripting.
3. Reference the sys_choice table directly
One user resolved their ordering issue by referencing the sys_choice table directly and filtering based on the dependent value, effectively bypassing the default lookup behavior. When you point your Lookup Select Box at sys_choice with a well-crafted reference qualifier (filtering by name, element, and inactive=false), you get more control over the query — and in some cases ^ORDERBYsequence does work when the table being referenced is sys_choice itself rather than a custom table.
4. Switch to a Reference variable type
If your use case allows it, switching from Lookup Select Box to a Reference variable type opens up the full range of reference qualifier and attribute controls. The ref_ac_order_by attribute is confirmed to work on Reference variables but not on Lookup Select Box types. You'd need to rework your qualifier to point at the source table directly, but ordering will behave as expected.
5. Query Business Rule on the source table
A Query Business Rule on the underlying table can enforce a default sort order, though it applies globally — not just to your catalog variable — so use this with caution.
The GlideAjax approach (option 1) is the most commonly adopted "real" fix when you need true sequence ordering without changing the variable type or label display. If you want, I can draft out the full Script Include and Catalog Client Script pair for your specific scenario — just let me know what table and field you're pointing at.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
19m ago
Hi @anthonyfall
Check this KB: KB0695435 Dependent variable of type "lookup select box" does not honor ORDERBY on reference qualifi...
Though ORDERBY will not work for Dependent variable of type "lookup select box" , but Sorting is supported using "ref_ac_order_by" in reference variables which is what should be used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7m ago
Thanks for the reply, but unfortunately the sequence field is not a reference type so using ref_ac_order_by will not help in my situation.
