Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Values not displaying in listcollect

Emp 53
Tera Contributor

Hi All,

My requirement is based on group i need to display users details in list collector.  for fetching this i written below script.

Script Include:

groupMember: function() {

var id = this.getParameter('sysparm_mem');

var idList = [];

var removemember = new GlideRecord('u_member');
removemember.addEncodedQuery('name=' + id);
removemember.query();
while (removemember.next()) {
idList.push(removemember.member.toString());
}

return 'sys_idIN' + idList.join(',');
},

client script:

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

g_form.clearValue('select_members_to_remove');

var ga = new GlideAjax('Details');
ga.addParam('sysparm_name', 'groupMember');
ga.addParam('sysparm_mem', newValue);
ga.getXML(callBackFunction);

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

var collectorName = 'select_members_to_remove';
var filterString = answer;

var myListCollector = g_list.get(collectorName);
myListCollector.reset();
myListCollector.setQuery(filterString);
}
} in alert i can able to see all details related to group but after that it's not working and below result displayed in listcollector field.

Emp53_0-1699556595046.png

 

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

To clarify, what are you seeing in the alert?  This will only work if it is a comma-separated list of sys_ids.  These sys_ids MUST exist on the table that is used as the List table for the list collector variable.  Are you testing this in Employee Center/Service Portal, or the native Service Catalog UI?

SanjivMeher
Mega Patron
Mega Patron

Are you sure you are querying the right field here? The table name is u_member, so I assume, the field name will be u_name. Also make sure the Name field is a reference field to user table.

removemember.addEncodedQuery('name=' + id);


Please mark this response as correct or helpful if it assisted you with your question.

Hi It's not reference member variable in single line text. other than user i am storing other info in same varibale so not using reference field.

Tai Vu
Kilo Patron
Kilo Patron

Hi @Emp 53 

I can see that you're trying to set the filter for the List Collector, I just wonder that why don't we use the Reference Qualifier inside the list collector variable.

With the Reference qualifier you only need a function in the Script Include (Client Callable unchecked).

Sample below.

var CLCatalogItemUtils = Class.create();
CLCatalogItemUtils.prototype = {
    initialize: function() {},

    getMember: function(group_id) {
        var arrUser = [];
        var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('group', group_id);
        grMember.query();
        while (grMember.next()) {
            arrUser.push(grMember.getValue('user'));
        }
        return 'sys_idIN' + arrUser.join(',');
    },

    type: 'CLCatalogItemUtils'
};

 

Screenshot 2023-11-10 at 16.38.53.png

javascript&colon;new global.CLCatalogItemUtils().getMember(current.variables.<your_group_variable>);

 

Cheers,

Tai Vu