The CreatorCon Call for Content is officially open! Get started here.

How to populate List Collector field based on Select box field in Catalog Item

Mahalakshmi Rav
Tera Contributor

Hi All,

In one catalog item, I have two fields:

  • Role Category → this is a Select box field 

  • Sub Category → this should be a list collector where user can select multiple roles. User wants this to be list collector as they want to select multiple roles

We have more than 200 sub values, so hardcoding in client script is not possible. 

My requirement is:

  • When user selects a Main Category, only related Sub Category values should show in the list collector.

  • Main is single select, Sub is multi select.

What is the simple and best way to do this?

  • Can we achieve this using a Reference Qualifier and a mapping table?

  • Or is there a simpler way without too much client-side scripting?

Any suggestions or examples would be very helpful.

9 REPLIES 9

Siddhesh Jadhav
Kilo Sage
Kilo Sage

Hi @Mahalakshmi Rav,

 

Yes, you can achieve this cleanly without hardcoding using a mapping table + reference qualifier:

 

1. Create a mapping table u_role_category_map

  • u_category → Reference to Role Category

  • u_role → Reference to sys_user_role

 

2. Script Include (client callable):

var RoleMapAjax = Class.create();
RoleMapAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  isPublic: function() { return true; },
  getRolesForCategory: function() {
    var cat = this.getParameter('sysparm_category');
    var ids = [];
    var gr = new GlideRecord('u_role_category_map');
    gr.addQuery('u_category', cat);
    gr.query();
    while (gr.next()) ids.push(gr.u_role.toString());
    return ids.join(',');
  },
  type: 'RoleMapAjax'
});

 

3. Catalog Client Script:

function getSubRoles() {
  var cat = g_form.getValue('role_category');
  if (!cat) return '';
  var ga = new GlideAjax('RoleMapAjax');
  ga.addParam('sysparm_name','getRolesForCategory');
  ga.addParam('sysparm_category',cat);
  ga.getXMLWait();
  var answer = ga.getAnswer();
  return answer ? 'sys_idIN' + answer : '';
}

 

4. Configure List Collector variable

  • Reference = sys_user_role

  • Reference qualifier = javascript:getSubRoles()

Result: When user selects a Role Category, the Sub Category list collector will only show the mapped roles.

 

Thanks & regards,
Siddhesh Jadhav
ServiceNow Community Rising Star 2025

 

Please mark this answer helpful and accepted if it resolved your query.

 

I would not suggest creating a table for this use case, instead use Decision table  feature.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Thank you for your suggestion @Siddhesh Jadhav , I'm already making using of an existing u_choice table from my instance. 

MahalakshmiRav_0-1758304436182.png

MahalakshmiRav_1-1758304442531.png

I tried creating a Script Include and calling it in the onChange Client Script using GlideAjax. It seems that addoption does not work with List Collector. Are there any other ways to implement this? The main functionality should allow sub category (jde_roles & jde_roles_to_be_removed) as List Collector fields.

On change client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || !newValue) return; // Skip if the form is loading or no category selected

    // Clear the List Collectors before populating
    g_form.clearOptions('jde_roles');
    g_form.clearOptions('jde_roles_to_be_removed');

    // Call Script Include to get roles for this category
    var ga = new GlideAjax('JDERoles');
    ga.addParam('sysparm_name', 'getRolesForCategory'); 
    ga.addParam('sysparm_category', newValue);
    ga.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');

        var roles = JSON.parse(answer); // Array of roles from Script Include

        console.log('Parsed roles array:', roles);

        // Populate both List Collectors with returned roles
        for (var i = 0; i < roles.length; i++) {
            g_form.addOption('jde_roles', roles[i].value, roles[i].label);
            g_form.addOption('jde_roles_to_be_removed', roles[i].value, roles[i].label);
        }
    });
}

Script Include:


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

    // Function to get roles based on the selected category
    getRolesForCategory: function() {
        var category = this.getParameter('sysparm_category'); // The selected role category from client

         gs.info('Category received from client: ' + category);


        var gr = new GlideRecord('u_choice'); 
        gr.addQuery('u_element', 'jde_new_roles'); 
        gr.addQuery('u_active', true);
        gr.addQuery('u_dependent_value', category);
        gr.orderBy('u_sequence');
        gr.query();

        var result = [];

        gs.info('Role matched: ' + gr.u_label + ' | dependent_value: ' + gr.u_dependent_value);


        while (gr.next()) {
            result.push({
                value: gr.u_value.toString(), // Stored backend value
                label: gr.u_label.toString()  // Display label
            });
        }
         gs.info('Returning JSON: ' + JSON.stringify(result));

        return JSON.stringify(result); // Send back to client script as JSON
    },

    type: 'JDERoles'
});

My catalog variables:
MahalakshmiRav_2-1758305130686.png

 

But this script is working when i make the field type as lookup selectbox.

Voona Rohila
Mega Patron
Mega Patron

Hi @Mahalakshmi Rav 

 

What is the dependency of subcategory and role category?

Do you have that dependencies in a excel file or do you have some relation between them?

 

You can consider Decision Tables concept here to return the categories as output if role is matched.

Call the decision table from the script include and use reference qualifier to send the role category to that SI.


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP