script not working

Rosy14
Tera Guru
Here I have a list collector type variable. I am getting the values and storing in list. I mentioned below which are not working. Can you help?
 
var conList = [];
    var accList = g_form.getValue('select_buying_agent_account');
    var acc = accList.split(',');
    flag = 0;
    var gr;
    for (var i = 0; i < acc.length; i++) {
       
        gr = new GlideRecord('customer_account');
        gr.query("sys_id",acc[i]); //NOT working
        gr.query();
        g_form.addInfoMessage("test");
        while (gr.next()) {
           g_form.addInfoMessage(gr.name); //Not working
            conList.push(gr.name);
        }

    }
9 REPLIES 9

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Can you just run this and show what you get in logs

 

var conList = [];
    var accList = g_form.getValue('select_buying_agent_account');
gs.log('accList= '+accList );
    var acc = accList.split(',');
    flag = 0;
    var gr;
gs.log('acc.length= '+acc.length);
    for (var i = 0; i < acc.length; i++) {
       gs.log('acc[i] '+acc[i]);
        gr = new GlideRecord('customer_account');
        gr.query("sys_id",acc[i]); //NOT working
        gr.query();
        g_form.addInfoMessage("test");
        while (gr.next()) {
           g_form.addInfoMessage(gr.name); //Not working
            conList.push(gr.name);
        }

    }
-Anurag

Rosy14_0-1701876178756.png

 

When are you running this? why is it running twice and why are we send the info messages twice?

-Anurag

Also i found the issue, try this

var conList = [];
    var accList = g_form.getValue('select_buying_agent_account');
gs.log('accList= '+accList );
    var acc = accList.split(',');
    flag = 0;
    var gr;
gs.log('acc.length= '+acc.length);
    for (var i = 0; i < acc.length; i++) {
       gs.log('acc[i] '+acc[i]);
        gr = new GlideRecord('customer_account');
        gr.addQuery("sys_id",acc[i]); //NOT working
        gr.query();
        g_form.addInfoMessage("test");
        while (gr.next()) {
           g_form.addInfoMessage(gr.name); //Not working
            conList.push(gr.name);
        }

    }
-Anurag