Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Answered

Using addCustomFilter() to filter lookups in dynamics 365

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
    sdfasdf 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
    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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,554 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,588 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans