List collector

Rosy14
Tera Guru

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.

Rosy14_0-1706022976981.png

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);

}
1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

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

View solution in original post

5 REPLIES 5

Rosy14
Tera Guru

Thanks all. Now it working.