List collector values cleared when new value selected in alert

Hemachithra
Tera Contributor

Hi

 

I have a List collector and I want to populate the values in a multi line text as well as display an alert message of the selection made .

 

But the alert message displays the entire values for all the items selected ,I want it to display only the values of item

Please help

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Hemachithra 

so you want to populate data from that list collector into another variable?

What's the desired business outcome? please share screenshots.

what script did you start with and what's the issue? what debugging have you done so far?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

There is a list collector and it displays topics at bottom ,this topic field has more values but due to word limit the list collector only displays certain text as shown below.

Hemachithra_0-1700475577992.png

The topics for the item is more but only few is displayed, as a workaround I want to fetch the values and display them in a multi line variable and as an alert message ,so I wrote client script and glide ajax to achieve it.
But the issue I'm facing is the alert message if I select the second item it not displays the topic for that item alone ,it displays values along with previous topics of the selected item.

Hemachithra_3-1700476139313.png

 

 

For selection of one item its corresponding topics is displayed as alert and its value is populated in the multi line variable ,
but when I select the second item the topic of the item along with previous selection topics is getting displayed. I want only the topics of the particular item displayed as alert.

Hemachithra_4-1700476212268.png

 

Also in multi line variable the topics of item must be added after a line break from the previous topics populated .



Danish Bhairag2
Tera Sage
Tera Sage

Hi @Hemachithra ,

 

Possible to share your script would be easy to help u out.

 

Thanks,

Danish

 

Sure the client script and script include used .

//STRY0015100 : NEW CONDUKTOR SUMMARY CATALOG ITEM
//Script to populate the list collector field in multi line text variable in catalog form.

var grpValues = Class.create();
grpValues.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
grpDetails: function(){
var grpVal = [];
var grpList = this.getParameter('sysparm_record');
var Value = grpList.split(',');


for(var i=0; i< Value.length; i++){
var names = new GlideRecord('u_conduktor_summary'); 
names.addQuery('sys_id',Value[i]);
names.query();
while(names.next())
{

grpVal.push(names.u_topics); 

}

}
return grpVal.join();
},
    type: 'grpValues'
});
//STRY0015100 : NEW CONDUKTOR SUMMARY CATALOG ITEM
//Script to populate the multi line text field.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
g_form.clearValue('topics_of_the_item_selected');
return;
}
if(newValue == ''){

g_form.clearValue('topics_of_the_item_selected'); // clear the values

}

g_form.clearValue('topics_of_the_item_selected');


var grpList = g_form.getValue('select_group_name_s');
alert(grpList);
var ga = new GlideAjax('grpValues');
ga.addParam('sysparm_name','grpDetails');
ga.addParam('sysparm_record',grpList);
ga.getXML(CallBack);

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

g_form.setValue('topics_of_the_item_selected', answer.toString().split(',').join( ), +'\n');
alert("Topics selected: "+answer);

}
}