Skip to main content

Notifications

Announcements

No record found.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,419 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,492 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans