Populate Options In lookup select box in Alphabetical order

pardhiv
Tera Contributor

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);
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@pardhiv 

in the variable attributes try to add this

give your field name

ORDERBYu_your_field

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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]

 

If the dropdowns are calling from the API and helps us to how we can add them Alphabetically.