Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 05:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 05:10 AM
Hi @Rosy14 ,
CONTAIONS AND LIKE are incorrect in above script
if (acc.indexOf("CASA") >= 0) {
gr.addQuery("company.name", "CONTAINS", "CASA");
} else {
gr.addQuery("company.name", "LIKE", "Li & Fung");
}
Mark it as solution proposed and helpful if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 05:22 AM
Tried this one. not working as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 08:57 AM
Hi @Rosy14 ,
Use below script
function asda_getContactBasedOnAccount() {
var ContactArray = [];
var acc = current.select_buying_agent_account.name;
var gr = new GlideRecord('customer_contact');
if (acc.indexOf("CASA") >= 0) {
gr.addEncodedQuery("company.nameLIKE*CASA*");
} else {
gr.addEncodedQuery("company.nameLIKELi & Fung");
}
gr.query();
while (gr.next()) {
ContactArray.push(gr.sys_id.toString());
}
return ContactArray;
}
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2023 05:14 AM
Rather than using gliderecord and returning an array of sys_ids, it is better to just return the encoded query you want to apply to the reference field. This prevents the system from hitting the database twice. Also, double check your encoded queries by filtering a list view and using the copy query function in the query breadcrumb.