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.

How to fetch the details of list collector in a list collector variable

Samiksha2
Mega Sage

Hi,

I have created catalog item in which I have a list collector variable -User(u_user--reference to sys_user table). another list collector- Roles(u_roles-reference to u_hardware table).

Here requirement is when we are selecting two value in the User variable the roles should be populated for both two values.

Suppose- User- a and b, then roles of both a and b should populate.

For one User, Roles is populating but for 2 it is not populating.

 

Script include:

getRole: function() {
var Sysid = [];
var role = this.getParameter('roles');
var gr = new GlideRecord("u_hardware");
gr.addQuery('u_user=' + role);
gr.query();
while (gr.next()) {

Sysid.push(gr.getValue('u_role'));
}
return JSON.stringify(Sysid);
},

 

Client script:(onChange of User)

var ga = new GlideAjax('getUserRole');
ga.addParam('sysparm_name', 'getRole');
ga.addParam('roles', newValue);
ga.getXML(setProducts);

function setProducts(response) {
var answers = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
g_form.setValue('u_role', answers);

}

 

Please help in this.

 

Thanks!

7 REPLIES 7

@Samiksha2 

 

use below code-

getRole: function() {
var Sysid = [];

var users=[];

users = this.getParameter('roles');

var gr = new GlideRecord("u_hardware");

for(var i=0;i<users.length;i++){

gr.addQuery('u_user=' +users[i]);
gr.query();
if (gr.next()) {

Sysid.push(gr.getValue('u_role'));
}

}

return JSON.stringify(Sysid);
},

 

Thanks,

Manjusha Bangale

Hi @manjusha_ ,

Thanks for reply. But it is not working

@Samiksha2 

check in what format users are displaying in the field users using gs.info();

Thanks,

Manjusha Bangale