- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 11:06 PM
Hi All,
In a requirement, need to copy List Collector Values into Multiline text field. For this, I created client script and script include. This is on a table when creating a new record on selection of values in list collector, need them to copy into multiline text.
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var grpList = g_form.getValue('group_id');
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('grp_names', answer);
alert(answer);
}
}
Script Include:
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_groups');
names.addQuery('sys_id',Value[i]);
names.query();
while(names.next())
{
grpVal.push(names.grp_name+'');
}
}
return grpVal.join();
},
type: 'grpValues'
});
I'm getting selected list values in alert but they are not populating into multiline text and getting null alert
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 08:39 AM
when the last value is removed the newValue is empty
so the onchange client script was not executing as the newValue check was present along with the isLoading
please update as below and it should work fine
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// when newvalue is empty/cleared
if(newValue == ''){
g_form.clearValue('grp_names'); // clear the values
}
g_form.clearValue('grp_names'); // clear the values
var grpList = g_form.getValue('group_id');
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('grp_names', answer.toString().split(',').join('\n'));
alert(answer);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 08:39 AM
when the last value is removed the newValue is empty
so the onchange client script was not executing as the newValue check was present along with the isLoading
please update as below and it should work fine
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// when newvalue is empty/cleared
if(newValue == ''){
g_form.clearValue('grp_names'); // clear the values
}
g_form.clearValue('grp_names'); // clear the values
var grpList = g_form.getValue('group_id');
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('grp_names', answer.toString().split(',').join('\n'));
alert(answer);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 08:54 AM
Hi Ankur,
Thanks a lot, it is working as expected. Thanks for all the answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 08:58 AM
It looks like you marked your own response as the correct answer, which may be confusing to others that read this later.
Please mark my response as correct and helpful if I was able to help you.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 09:03 AM
Also request to mark comments/post as helpful wherever they helped.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 11:19 PM
Hello,
Client script is correct,but SI is not,Here is the updated code of script include
var grpValues = Class.create();
brpValues.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_groups');
names.addQuery('sys_id',value[i]);
names.query();
while(names.next())
{
grpVal.push(names.grp_name+''); //please give right bacckend value of grp_name
}
}
return grpVal.join();
},
type: 'grpValues'
});
Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.
Regards
Yash.K.Agrawal