Advanced reference qualifer taking time

Community Alums
Not applicable

Hi Team,

We have an OOTB reference field 'Account To' on Account Relationship table. There is already a advanced reference qualifier written as below which works fine but we need to restrict below to only show parent accounts

javascript:var ret='customer=true'; if (current.relationship_type.to == 'partner') ret = 'partner=true';  ret + '^sys_id!=' + current.from_company

 

For that we have written script include as below but it takes lot of time to fetch the records whereas above OOTB qualifier does not take much time.

Infact my script include returns only 50000 records whereas above returns 1.4Lakhs still above one is fast and mine below is slow?

getAccount: function(from_company) {
        var arr = [];

        var gr = new GlideRecord('customer_account');
        gr.addEncodedQuery('account_parentISEMPTY^customer=true^sys_id!='+from_company);
        gr.query();
        while (gr.next()) {
            arr.push(gr.sys_id.toString());
        }

       return 'sys_idIN' + arr;
     
    },
1 REPLY 1

Slava Savitsky
Giga Sage

Looping through the list to collect the sys_ids and then querying the table by a list of sys_ids is very inefficient. In fact, you query the database twice for no reason. All you need to do is put your encoded query directly into the reference qualifier like this:

 

javascript: 'account_parentISEMPTY^customer=true^sys_id!='+current.from_company