- 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-23-2020 11:49 PM
Hi Nani,
please share form screenshot
1) list field group_id refers to u_groups table
2) you are querying the same table in GlideRecord
3) on the u_groups table there is grp_name field which you want to push into array and show in multi line text
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 12:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 12:15 AM
Hi,
the table is incorrect during the query
please give the table name as below the one in blue color
var names = new GlideRecord('****_olcm_roles');
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 12:31 AM
Hi Ankur, for some security reasons, I replaced the table name with some dummy name.
please find the exact script include code that I'm using,
var brpValues = Class.create();
brpValues.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getDetails: function(){
var retVal = [];
var arrayList = this.getParameter('sysparm_record');
var arrayValue = arrayList.split(',');
for(var i=0; i< arrayValue.length; i++){
var details = new GlideRecord('x_usaa3_user_secur_olcm_roles');
details.addQuery('sys_id',arrayValue[i]);
details.query();
while(details.next())
{
retVal.push(details.role_name+'\n');
}
}
return retVal.join();
},
type: 'brpValues'
});
I'm getting null value...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2020 12:34 AM
Hi,
with which user you are testing? admin or non-admins
try giving logs; check what comes in array
var brpValues = Class.create();
brpValues.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getDetails: function(){
var retVal = [];
var arrayList = this.getParameter('sysparm_record');
var arrayValue = arrayList.split(',');
for(var i=0; i< arrayValue.length; i++){
var details = new GlideRecord('x_usaa3_user_secur_olcm_roles');
details.addQuery('sys_id',arrayValue[i]);
details.query();
while(details.next())
{
retVal.push(details.role_name + ',');
}
}
gs.info('Array is' + retVal);
return retVal.join();
},
type: 'brpValues'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader