Display Value of list collector in client script Service Catalog

Brian Lancaster
Tera Sage

I have a requirement where I need to display what was selected in a list collector in a text box along with some other fields.  I tried using g_form.getDisplayBox('variable name').value which has been mentioned in some other posts for reference fields but that does not seem to work for list collectors.  How can I achieve this requirement.

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

I ended up just using a script include for this.

View solution in original post

9 REPLIES 9

Never got a solution or figured it out.  This is no longer a requirement for me.

It doesn't looks like it is possible to do it using g_form.  What I ended up doing was using script include to send my array of sys_ids and then returned an array of the display values and then called a function to update my multi-line text box.

Hi Brian,

I'm working on the similar requirement. Can you please post the script include you have used to return the display values of list collector? Thank you.

I had to use an on change client script that would call the script include sending it the value(s).  The script include would then return an array of the field that contained what I wanted to display.  In essence the field that was set to display.  In my case I think it was called name.  I don't have access to the code anymore as I no longer work for that company.  I will see if I can reproduce it.

Here is the script include I used.  It allows me to query any table.  The Comments lines at the top are the parameters to use.

Table data query script include
//Get Data from a service now table.

//parameters:
//sysparm_query_table : name of tabel
//sysparm_query_encodedQuery : encoded query to run on the table
//sysparm_query_fields : fields to return from table
//sysparm_query_order: field to order data by


var TableDataQuery = Class.create();
TableDataQuery.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getList: function () {
        var table = this.getParameter('sysparm_query_table');
        var encodedQuery = this.getParameter('sysparm_query_encodedQuery');
        var propertiesString = this.getParameter('sysparm_query_fields');
		var orderBy = this.getParameter('sysparm_query_order');
        var request = new GlideRecord(table);
        request.addEncodedQuery(encodedQuery);
		request.orderBy(orderBy);
        request.query();
        var list = [];
        while (request.next()) {
            if (propertiesString != null && propertiesString != "") {
                var responseObject = {};
                var properties = propertiesString.split(",");
                for (var i = 0; i < properties.length; i++) {
                    gs.print(properties[i]);
                    responseObject[properties[i]] = request[properties[i]].toString();
                }
                list.push(responseObject);
            } else {
                list.push(request);
            }          
        }
        return JSON.stringify(list);
    },
    type: 'TableDataQuery'
});