A little background info:
- I have a Customer (customerid) lookup field where the user selects a parent account.
- I have a Location (ars_location) lookup field where the user selects a child account of the parent account.
--------------------------------------------------------------------------------------------
I am currently trying to add a custom filter to my Customer field so that only parent accounts show up in the results. I have created a view so I first tried this,
function setLookupView() { Xrm.Page.getControl("customerid").setDefaultView("{B9300D26-1337-E611-80EA-C4346BDCF181}"); }
But what this does is filter the accounts after I click the "View More Records" button and does not filter in the the inline results.
--------------------------------------------------------------------------------------------
Next, I tried adding a presearch/customfilter to it. This is what I did:
function parentFilterLookup() { //Check if the control exist on the form if (Xrm.Page.getControl("header_process_customer") != null) { // add the event handler for PreSearch Event Xrm.Page.getControl("header_process_customer").addPreSearch(addFilter); } } function addFilter() { var fetchQuery; try { //Build fetch fetchQuery = "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='null' />" + "</filter>"; //add custom filter Xrm.Page.getControl("header_process_customer").addCustomFilter(fetchQuery); } catch (e) { Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message)); } }
I have also tried replacing "header_process_customer" with "customerid". Both to no success.
--------------------------------------------------------------------------------------------
What's strange is that I already have a working presearch/customfilter on a different lookup field on the same form. This is the code for that:
function filterLookup() { //Check if the control exist on the form if (Xrm.Page.getControl("header_process_ars_location") != null) { // add the event handler for PreSearch Event Xrm.Page.getControl("header_process_ars_location").addPreSearch(addFilter); } } function addFilter() { var customerID = null; var customerLookup; var fetchQuery; try { //Check if control exist on form if (Xrm.Page.getControl("header_process_customer") != null && Xrm.Page.getControl("header_process_customer").getAttribute().getValue() != null) { //Get Account lookup value customerLookup = Xrm.Page.getControl("header_process_customer").getAttribute().getValue(); //Get the account id customerID = customerLookup[0].id; } //Build fetch if (customerID != null || customerID != undefined) { fetchQuery = "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + customerID + "' />" + "</filter>"; //add custom filter Xrm.Page.getControl("header_process_ars_location").addCustomFilter(fetchQuery); } } catch (e) { Xrm.Utility.alertDialog("addFilter Error: " + (e.description || e.message)); } }
What could I be doing wrong? Any suggestions?
*This post is locked for comments
Hi,
You are adding same function to same control two times so it will be override with last function added on form.
They are on the same form but the functions are implemented in separate libraries. I tried renaming them but it did nothing.
Hi Brian,
You have two addFilter() functions here. Are both on the same form? Try renaming them to addFilterCustomer() and addFilterLocation().
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156