Look up select box reference qualifier not sorting by sequence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 07:22 PM
I have a look up select box variable on my record producer called subcategory which is depend on another variable category.
Now i have created a look up select box variable and used the referecnce qualifier below still its sorting alphabetically not by sequence field on sys_choice table.
@Ankur Bawiskar Can you please guide what can be done to achieve this?
Regards,
Debasis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2025 03:18 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2025 10:28 PM
Hi @Debasis Pati ,
after some research on this I found ORDERBY doesn't work (in the portal environment but works in the native refer my first response for native UI) in this case
You can go this approach instead
1. change the variable type to select box
2. create a client callable script include
var getChoices = Class.create();
getChoices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getChoices: function() {
var arr = [];
var includeNone = this.getParameter('sysparm_include_none');
if (includeNone && includeNone == 'true')
arr.push({
label: '-- None --',
value: ''
});
var chGr = new GlideRecord('sys_choice');
chGr.addEncodedQuery(this.getParameter('sysparm_filter'));
chGr.query();
while (chGr.next()) {
arr.push({
label: chGr.getValue('label'),
value: chGr.getValue('value')
});
}
return JSON.stringify(arr);
},
type: 'getChoices'
});with onChange client script on the category variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var subcatVarName = 'subcategory'; //update the subcategory with your variable backend name if required
g_form.clearOptions(subcatVarName);
var ga = new GlideAjax('getChoices');
ga.addParam('sysparm_name', 'getChoices');
ga.addParam('sysparm_include_none', true); //put this to false if none choice not required
ga.addParam('sysparm_filter', 'ORDERBYsequence^language=en^name=incident^element=subcategory^dependent_value=' + newValue);
ga.getXMLAnswer(function(answer) {
var arr = JSON.parse(answer);
if (arr && arr.length) {
arr.forEach(function(i) {
g_form.addOption(subcatVarName, i['value'], i['label']);
});
}
});
}I have added comments in the two places (update the subcategory with your variable name if it's different) and include none as option or not
this make sures the choices are displayed in the specified order
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
