Auto-populate list collector values based on another select box variable

Koyel Guha
Tera Contributor

Hi,

I have variable A (selectbox) and variable B(list collector). When I select any option from variable A for eg. "x1" then variable B referencing a customized table having a field u_description which will filter u_description contains "read" keyword and u_description contains "x1". Based on the condition, it will display the one or multiple results from the table in the varible B.

 

I have tried with a ref qual in the variable B but it is not working based on the selection.

 

javascript:"u_descriptionLIKEread^u_descriptionLIKE"+current.variables.please_select_the_fileserver_where_the_shared_folder_is_located;

 

Would appreciate your help on this.

 

Thanks.

 

9 REPLIES 9

When the list collector value is showing all value. When I am selecting BRCGNTDFS001P, the list collector values are not changing.

KoyelGuha_1-1747230957940.png

KoyelGuha_4-1747231311218.png

 

KoyelGuha_3-1747231167302.png

 

KoyelGuha_2-1747231101156.png

 

Thanks

 

@Koyel Guha 

you are filtering so it won't auto populate the list collector?

You want to auto populate the list collector or restrict it?

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

Hi Ankur,

Based on read and the fileserver name selected in the description, it should show only those results in the list collector not all the group names from the table.

If A selected, it should check for all the values of A and read in the description and show those results. 

If there is only one record then one should show in LC. If 4 then 4 records.

Thanks.

@Koyel Guha 

so what script did you start and where are you stuck?

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

Hi Ankur,

This is the script : 

var FilterActiveDirectory = Class.create();
FilterActiveDirectory.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getFilteredSysIds: function() {
        var input = this.getParameter('sysparm_id');
        var info = [];

        var gr = new GlideRecord('u_active_directory_groups');
        gr.addEncodedQuery('u_descriptionLIKEread^u_descriptionLIKE' + input);
        gr.query();

        while (gr.next()) {
            info.push(gr.u_query_name.toString());
        }

        return info.join('!');
    }
});
On change : 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        g_form.clearOptions('please_select_the_following');
        return;
    }

    var ga = new GlideAjax('FilterActiveDirectory');
    ga.addParam('sysparm_name', 'getFilteredSysIds');
    ga.addParam('sysparm_id', newValue);
    ga.getXMLAnswer(function(response) {
        if (!response) {
            g_form.setValue('please_select_the_following', '');
            return;
        }

        var result = response.split('!');
        var filterString = 'u_query_nameIN' + result.join(',');
        g_form.setValue('please_select_the_following', '');
        g_form.setReferenceQual('please_select_the_following', filterString);
    });
}
 
Thanks