Populate Options In lookup select box in Alphabetical order
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 07:07 PM
HI
I have a lookup select box, where options are populated using script how do I populate them in Alphabetical order.
This is how data looks in order currently.
Confguration Item [cmdb_ci] , AIX Server [cmdb_ci_aix_server] , server [cmdb_ci_server]
//Script include
getParentClass: function(childci, relType) {
var hirclass = [];
var parentclass = [];
var dependentCi = childci;
var reltype = relType;
var cl = new GlideRecord('cmdb_ci');
cl.query('sys_id', dependentCi);
cl.query();
if (cl.next()) {
hirclass.push(cl.sys_class_name);
}
var cond = 0;
for (var incr = 0; cond <= 0; incr++) {
var hir = new GlideRecord('sys_db_object');
hir.addQuery('name', hirclass[incr]);
hir.addEncodedQuery('super_class!=NULL');
hir.query();
if (hir.next()) {
hirclass.push(hir.super_class.name);
} else {
cond = 1;
break;
}
}
for (var incrm = 0; incrm < hirclass.length; incrm++) {
var sugg = new GlideRecord('cmdb_rel_type_suggest');
sugg.addQuery('dependent_class', hirclass[incrm]);
sugg.addQuery('cmdb_rel_type.sys_id', reltype);
sugg.query();
while (sugg.next()) {
parentclass += sugg.sys_id + ',';
}
}
return 'sys_idIN' +parentclass;
},
//REFERENCE Qulifier
javascript: new Populatefields().getParentClass(current.variables.child_ci,current.variables.relationship_type);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 07:25 PM
in the variable attributes try to add this
give your field name
ORDERBYu_your_field
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 08:14 PM
This orders the field by backend name
This is how data looks in order currently.
Confguration Item [cmdb_ci] , AIX Server [cmdb_ci_aix_server] , server [cmdb_ci_server]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2025 02:11 PM
If the dropdowns are calling from the API and helps us to how we can add them Alphabetically.