How to push multiple values in multiple line text field in catalog.

Community Alums
Not applicable

Hi All,

I have one cat item with 4 fields. Req for (List Collector) & UserId, Dept, Title (Multiline Text)

Please have a look below.

find_real_file.png

 

I will select Abel Tuter first in list collector, then it should populate corresponding values in the below three fields. After that i will select another user Abraham Lincoln, the it should populate corresponding values in below three fields with comma separated to the existing.

How can i achieve this. Here is my code, it is working for single selection not for multiple.

Client Script :

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

var getReqUser = g_form.getValue('requestd_for');
var ga = new GlideAjax('Populate_dept');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user_id', getReqUser);
ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {
alert('In');
var answer = response.responseXML.documentElement.getAttribute("answer").split(',');
alert(answer);

g_form.setValue('uId', answer[0]);
g_form.setValue('ttle', answer[1]);
g_form.setValue('deprtmnt', answer[2]);
}
}

 

Script Include : 

var Populate_dept = Class.create();
Populate_dept.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var userr = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', userr);
gr.query();
if (gr.next()) {
gs.log('Hi Sira');
return gr.user_name + ',' + gr.title + ',' + gr.department.toString();
}
},
type: 'Populate_dept'
});

 

Regards,

Sirraj

1 ACCEPTED SOLUTION

Even though you can't select multiple values at one time via this portal interface, the variable is still a list collector that is storing multiple values, so the script has to accommodate that.  The below client script will work.

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

var getReqUser = g_form.getValue('requestd_for');
var ga = new GlideAjax('Populate_dept');
ga.addParam('sysparm_name', 'getUserDetails');
ga.addParam('sysparm_user_id', getReqUser);
ga.getXML(HelloWorldParse);

function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);

g_form.setValue('uId', answer.user);
g_form.setValue('ttle', answer.title);
g_form.setValue('deprtmnt', answer.dept);
}
}

and the script include

var Populate_dept = Class.create();
Populate_dept.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetails: function() {
var obj = {};
obj.user = '';
obj.title = '';
obj.dept = '';
var userr = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', userr);
gr.query();
while (gr.next()) {
if(obj.user == ''){
obj.user = gr.user_name.toString();
}
else{
obj.user = obj.user + ',' + gr.user_name.toString();
}
if(obj.title == ''){
obj.title = gr.title.toString();
}
else{
obj.title = obj.title + ',' + gr.title.toString();
}
if(obj.dept == ''){
obj.dept = gr.department.name.toString();
}
else{
obj.dept = obj.dept + ',' + gr.department.name.toString();
}
}
return JSON.stringify(obj);
},
type: 'Populate_dept'
});

View solution in original post

13 REPLIES 13

Brad Bowman
Kilo Patron
Kilo Patron

When you have multiple values in a list collector, it's a comma-separated string, so you'll need to change your script include to return and process all of the records

gr.addQuery('sys_id', 'IN', userr);
gr.query();
while (gr.next()) {

Then in the while loop you'll want to push the values to an array and return the array as a string.  On the client side you'll need to parse the array differently.  I'll try to work out a mock-up in case you get stuck.

Community Alums
Not applicable

Hi Brad,

Thank you for the suggestion. But i just want to highlight this, i will not select multiple values from list collector at a time. I will select only one value from list collector then it should populate other fields. 

After populating other fields, then again will select my second value from list collector. Then it should populate other fields value. These field value should set in multiline text with existing values.

When you select the second value from the list collector, the first will still be in the right 'selected' box, correct - or are you removing the first value then adding a different value the second time?

Community Alums
Not applicable

It will be still there. In portal it is not showing as list collector, there it s showing a dropdown. 

Please refer the below screenshot. This is i have selected first value from list collector.

find_real_file.png

 

Please refer the second screenshot with two user selection.

find_real_file.png

 

So in portal it is not showing as list collector(which is expected one itseems), it is showing as dropdown. I can select one by one only. If i select two users, i want their corresponding values should be displayed like this. Please refer below.

 

find_real_file.png

Regards,

Sirraj