How to fetch the details of list collector in a list collector variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 02:14 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 06:32 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2023 06:49 AM
Hi @manjusha_ ,
Thanks for reply. But it is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 02:40 AM
check in what format users are displaying in the field users using gs.info();
Thanks,
Manjusha Bangale