Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Srikanth_Peru
Tera Guru

In ServiceNow using the list collector was tricky and helpful where we can able to perform/request more values in a single request

Let’s understand the list collector functionality

Selection of Multiple Items: Users can select multiple items from a list presented in the catalog item form. This is particularly useful when users need to choose multiple related options or entities, such as software applications, services, asset or group.

Benefits:

  • User Experience: Simplifies the selection process for users needing multiple items.
  • Efficiency: Reduces the need for multiple catalog items by allowing consolidated selections.
  • Flexibility: Supports dynamic and conditional item selections based on various criteria.

Let’s understand with a simple use case

Example: User need to be removed from the group he/she present (looks simple ryt )

NOTE: Auto populate the groups based on the user they have selected customer wants to have the auto population of group on the list collector

 

SrikanthPeruma_1-1719299171583.png

Script include: 

var Populategroup = Class.create();
Populategroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    userDetails: function() {
        var sys_id = [];
        var user = this.getParameter("sysparm_user");
        var userList = new GlideRecord("sys_user_grmember");
        userList.addQuery("user", user);
        userList.query();
        while (userList.next()) {
            var group = userList.group.sys_id.toString();
            var grp = new GlideRecord("sys_user_group");
            grp.get("sys_id", group);
            if (grp.sys_id) {
                sys_id.push(group);
            }
        }
        return sys_id.toString();
    },

    type: 'Populategroup'
});

Client Script: Populate group based on user selected

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var user = g_form.getValue("requested_for");
    var ga = new GlideAjax('Populategroup'); // Populategroup is the script include class 
    ga.addParam('sysparm_name', 'userDetails'); // userDetails is the script include fucntion method 
    ga.addParam('sysparm_user', user); // Set parameter sysparm_user to 'user' 
    ga.getXML(userPopulate);


    // the callback function for returning the result from the server-side code
    function userPopulate(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue("list_of_groups", answer);
    }

Result:

 

gif.gif

 

Thanks and Regards,

Srikanth 

LinkedIn: https://www.linkedin.com/in/perumandla-srikanth/  

 

 

 

 

wait a min.gif

 

Wondering will it work on the native as well 

 

yes-daniel-bryan.gif

 

Result on the Native: 

gif native.gif

 Happy Learning😉