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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
11manish Profile Picture

11manish 174

#2
ManoVerse Profile Picture

ManoVerse 58 Super User 2026 Season 1

#3
Niki Patel Profile Picture

Niki Patel 42

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans