Too many choices in catalog item variable

Mike Hashemi
Kilo Sage

I am trying to create a catalog item. For the first variable, I need the user to select from a list of specific CMDB classes. I think the Lookup Multiple Choice variable type is the best option and I have the following settings:

 

  • Lookup from table: sys_db_table
  • Lookup value field: Label
  • Unique values only: true
  • Reference qualifier: javascript:new PhoneSystemClassQualifier().getPhoneSystemClasses();

The associated script include looks like: 

var PhoneSystemClassQualifier = Class.create();
PhoneSystemClassQualifier.prototype = {
    initialize: function() {},

    getPhoneSystemClasses: function() {
        var classes = [
            'u_cmdb_ci_five9_phone_system',
            'u_cmdb_ci_kandy_business_solution_phone_system',
            'u_cmdb_ci_microsoft_teams_phone_system',
            'u_cmdb_ci_synoptek_efax'
        ];

        var gr = new GlideRecord('sys_db_object');
        gr.addQuery('name', classes);
        gr.query();

        var sysIds = [];
        while (gr.next()) {
            sysIds.push(gr.get('sys_id'));
        }

        if (sysIds.length === 0) {
            return 'sys_idISEMPTY';
        } else {
            return 'sys_idIN' + sysIds.join(',');
        }
    },

    type: 'PhoneSystemClassQualifier'
};

 

When I go "Try It", SN is showing all classes in the CMDB. What am I missing?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Mike Hashemi 

Why not have a select box i.e. drop down with 4 choices?

if not then why not apply simple filter condition on that variable itself rather than script include and ref qualifier?

AnkurBawiskar_0-1735968735189.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

6 REPLIES 6

@Mike Hashemi 

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.

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

Nothing else is working so I guess this is going to have to be it.