Michael Jones -
Giga Sage

As you are calling this client-side, you will need to use GlideAjax to send a request to the server and return the information. 

Here is an example that pulls records from the cmdb_ci_spkg table and populates a select box named "software" with options. 

 

Name: populateSelectBox

Client-Callable = true

 

var populateSelectBox = Class.create();
populateSelectBox.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    type: 'populateSelectBox',
    getSoftware: function() {
		
		//Queries the cmdb_ci_spkg table for all records with the attribute showInPortal
		//and constructs a JSON Object as a response with name and sys_id
        var retStr = [];
        var jStr = '[';
        var gr_software = new GlideRecord('cmdb_ci_spkg');
        gr_software.addEncodedQuery('attributesLIKEshowInPortal');
        gr_software.orderBy('name');
        gr_software.query();
        while (gr_software.next()) {
            jStr += '{"name":"' + gr_software.getValue('name') + '","id":"' + gr_software.getValue('sys_id') + '"},';
        }
        jStr = jStr.substring(0, jStr.length - 1);
        jStr += "]";
        return jStr;
    }
});

 

Then, in your catalog call this script onload to set the values (this assumes that none was included in the variable definition). Just replace "software" with the name of your variable. 

 

function onLoad() {

//Call GlideAjax to populate the software list
	
    var ga = new GlideAjax('populateSelectBox');
    ga.addParam('sysparm_name', 'getSoftware');
    ga.getXML(ajProcessor);
	

    function ajProcessor(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        var obj = JSON.parse(answer);
        var i;
        for (i = 0; i < obj.length; i++) {
//replace software with your variable name
            g_form.addOption('software', obj[i].id, obj[i].name);
        }
    }
}

 

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!