- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 04:16 AM
Hi
In List collector variable, enduser will select multiple users while filling the catalog form.
Here issue I am facing is returning only one user's name in the alert window.
There are multiple users in List collector variable, but only one user is returning.
Below is the script, please help me, how can solve this issue.
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var sysID = g_form.getUniqueValue();
var listVar = new GlideAjax('GetListCollectorVariables');
listVar.addParam('sysparm_name', 'AusGiftCardlistcollector');
listVar.addParam('sysparm_record_id', sysID);
listVar.getXML(GetVariablesfromQuestionTable);
function GetVariablesfromQuestionTable(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('Sysid Values ' + answer);
}
}
Script Include:
var GetListCollectorVariables = Class.create();
GetListCollectorVariables.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
AusGiftCardlistcollector : function()
{
var par = this.getParameter('sysparm_record_id');
var query = 'table_nameLIKEsn_hr_core_case^question.name=seltdRecipients^ORDERBYDESCsys_created_on';
var question = new GlideRecord('question_answer');
question.addEncodedQuery(query);
question.addQuery('table_sys_id', par);
question.query();
if(question.next())
{
var values = question.value;
var splitvalues = values.split(",");
for(var i=0;i<=splitvalues.length;i++)
{
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', splitvalues[i]);
user.query();
while(user.next())
{
var names = user.getValue('u_name');
return names;
}
}
}
},
type: 'GetListCollectorVariables'
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 06:14 AM
Hi,
//use onLoad on RITM form
var selectedUsers=g_form.getValue('variables.seltdRecipients'); // this will return comma separated values.
pass this value in your method.
//script include code
var names =''
var par = this.getParameter('sysparm_record_id');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id','IN', par);
user.query();
while(user.next()) {
names +=','+ user.getValue('u_name');
}
return names;
In your present code also
return statement should be out side for and while loop.
Please Hit ✅Correct, ⭐️Helpful depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 05:10 AM
Please Use This Script :
function onLoad() {
var sysID = g_form.getUniqueValue();
var listVar = new GlideAjax('GetListCollectorVariables');
listVar.addParam('sysparm_name', 'AusGiftCardlistcollector');
listVar.addParam('sysparm_record_id', sysID);
listVar.getXML(GetVariablesfromQuestionTable);
function GetVariablesfromQuestionTable(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('Sysid Values ' + answer);
}
}
Script Include :
var GetListCollectorVariables = Class.create();
GetListCollectorVariables.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { AusGiftCardlistcollector : function() {
var par = this.getParameter('sysparm_record_id');
var query = 'table_nameLIKEsn_hr_core_case^question.name=seltdRecipients^ORDERBYDESCsys_created_on';
var question = new GlideRecord('question_answer');
question.addEncodedQuery(query);
question.addQuery('table_sys_id', par);
question.query();
if(question.next()) {
var values = question.value;
var splitvalues = values.split(",");
var names ="";
for(var i=0;i<=splitvalues.length;i++) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', splitvalues[i]);
user.query();
while(user.next()) {
names += user.getValue('u_name') +',';
return names;
}
}
}
},
type: 'GetListCollectorVariables'
});
Mark if this is helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 05:50 AM
Hi Sririnivas,
Thanks for the response.
Alert Box is returning only one name, there is no difference.
List collector has 5 users, but is displaying only one user name on alert box.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 06:14 AM
Hi,
//use onLoad on RITM form
var selectedUsers=g_form.getValue('variables.seltdRecipients'); // this will return comma separated values.
pass this value in your method.
//script include code
var names =''
var par = this.getParameter('sysparm_record_id');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id','IN', par);
user.query();
while(user.next()) {
names +=','+ user.getValue('u_name');
}
return names;
In your present code also
return statement should be out side for and while loop.
Please Hit ✅Correct, ⭐️Helpful depending on the impact of the response