Script Include

Rosy14
Tera Guru

Hi,

I want to filter a ref field based on another field(Ref). If that field.name contains XXXX, then the 2nd field will show all records where field.comany.name contains XXXX. Below returning all records

function asda_getContactBasedOnAccount() {

    var ContactArray = [];
    var acc = current.select_buying_agent_account.name;
    var gr = new GlideRecord('customer_contact');
    if(acc.toString().indexOf("CASA") >= 0)
    {
        gr.addEncodedQuery("company.nameCONTAINSCASA");
       
    }else{
     gr.addEncodedQuery("company.nameLIKELi & Fung");
    }
   
    gr.query();
    while (gr.next()) {
        ContactArray.push(gr.sys_id.toString());
    }
    return ContactArray;

}
8 REPLIES 8

javascript:if(current.select_buying_agent_account.name.indexOf("CASA") >= 0) 'company.nameCONTAINSCASA';else 'company.nameCONTAINSLi & Fung';

 

this returning list contains Li & Fung only.

Can you help.

I mean in your script include, do the if/else and return the encoded query instead of the getting the sys_id query.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Rosy14 ,
I trust you are dioing great.
Please find th eupdated code 

 

function asda_getContactBasedOnAccount() {
    var ContactArray = [];
    var accName = current.select_buying_agent_account.name.toString();
    var gr = new GlideRecord('customer_contact');

    if (accName.indexOf("XXXX") >= 0) {  // Replace "XXXX" with the specific string you're checking for
        // Dynamically filter based on the accName value
        gr.addEncodedQuery("company.nameCONTAINS" + accName);
    } else {
        // Optionally, handle the case where "XXXX" is not found in accName
        // You can remove this else block if it's not needed
        gr.addEncodedQuery("company.nameCONTAINSdefault_value"); // Replace "default_value" with a default string if needed
    }

    gr.query();
    while (gr.next()) {
        ContactArray.push(gr.sys_id.toString());
    }
    return ContactArray;
}

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Rosy14
Tera Guru
javascript:var rt='';if(current.variables.select_buying_agent_account.name.toString().indexOf("CASA") >= 0) rt='company.nameCONTAINSCASA';else rt='company.nameCONTAINSLi & Fung';rt;

Inside Ref qual it is working.