web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Using addCustomFilter() to filter lookups in dynamics 365

(0) ShareShare
ReportReport
Posted on by 35

Hi all,

i am using addCustomFilter() and the addPreSearch method to filter the "account" lookup in the opportunity entity, but it only works when i click the search button and when i try to type in field the filter doesn't work. is this normal? 

OpportunityTest.setParentAccountIdFilter function is set in the form Onload event handler.

pastedimage1601906642505v1.pngpastedimage1601906811235v2.png

var OpportunityTest = window.OpportunityTest || {};
OpportunityTest.setParentAccountIdFilter = function (executionContext) {

    // get the form context
    formContext = executionContext.getFormContext();
    formContext.getControl("parentaccountid").addPreSearch(OpportunityTest.filterCustomerAccounts);
}

OpportunityTest.filterCustomerAccounts = function () {

    // Only show accounts with the type 'marketingonly'equal to yes
    var customerAccountFilter = ""   ""  
        " ";
    formContext.getControl("parentaccountid").addCustomFilter(customerAccountFilter, "account");
} 

I have the same question (0)
  • Verified answer
    gopi.royal999@gmail.com Profile Picture
    430 on at

    I haven't tested it though, did you try by disabling Recent Records on the lookup?

  • Verified answer
    sdfasdf Profile Picture
    842 on at

    Since you're using the PreSearch event, this event only gets triggered when you tried to do the search. Maybe you don't need to use the PreSearch event here. Instead, just add your custom filters using the OnLoad event, like this:

    var OpportunityTest = window.OpportunityTest || {};
    OpportunityTest.setParentAccountIdFilter = function (executionContext) {

    // get the form context
    formContext = executionContext.getFormContext();
    // Only show accounts with the type 'marketingonly'equal to yes
    var customerAccountFilter = "<filter type='and'>" + "<condition attribute = 'marketingonly' operator = 'eq' value = '1' />" +
    "</filter > ";
    formContext.getControl("parentaccountid").addCustomFilter(customerAccountFilter, "account");

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 47 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
Pallavi Phade Profile Picture

Pallavi Phade 32

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans