Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 07:16 AM
Hi,
I have a list collector ref to customer_account. When I select records here in a new field it will populate the name-number of those records. Tried onchange client script not working in UI/Portal.
The table is in Global scope and RP is another. I checked allow configuration as well.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var comDetails = [];
var name_num;
var comL = g_form.getValue('additional_accounts');
g_form.addInfoMessage(comL);
var com = comL.split(',');
for (var i = 0; i < com.length; i++) {
var gr = new GlideRecord('customer_account');
gr.query('sys_id', com[i]);
gr.query();
while (gr.next()) {
g_form.addInfoMessage(gr.getValue('sys_id'));
name_num = gr.name + "-" + gr.number;
comDetails.push(name_num);
}
}
g_form.setValue('additional_companies_details',comDetails);
}
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 08:28 PM
Hi @Rosy14
You can give my adjustment a try.
#Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('AccountDetails'); //script include name
ga.addParam('sysparm_name', 'getAccountDetails'); //function name within script include
ga.addParam('sysparm_account_ids', newValue);
ga.getXMLAnswer(function(answer){
var result = answer; //just split the answer if you'd like to loop through each element
g_form.setValue('additional_companies_details', result);
});
}
#Script Include
var AccountDetails = Class.create();
AccountDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAccountDetails: function() {
var accountIDs = this.getParameter('sysparm_account_ids');
var accounts = [];
var gr = new GlideRecord('customer_account');
gr.addQuery('sys_id', 'IN', accountIDs);
gr.query();
while(gr.next()){
var account = gr.getValue('name') + "-" + gr.getValue('number');
accounts.push(account);
}
return accounts.join(',');
},
type: 'AccountDetails'
});
Cheers,
Tai Vu
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 10:51 PM
Thanks all. Now it working.