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");
} 

  • Verified answer
    sdfasdf Profile Picture
    840 on at
    RE: Using addCustomFilter() to filter lookups in dynamics 365

    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");

    }

  • Verified answer
    gopi.royal999@gmail.com Profile Picture
    430 on at
    RE: Using addCustomFilter() to filter lookups in dynamics 365

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

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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Adis Profile Picture

Adis 136 Super User 2025 Season 1

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 81

#3
Jonas "Jones" Melgaard Profile Picture

Jonas "Jones" Melgaard 77 Super User 2025 Season 1

Product updates

Dynamics 365 release plans