addCustomFilter (Client API reference)

Adds filters to the results displayed in the lookup. Each filter will be combined with any previously added filters as an AND condition.

Control types supported



formContext.getControl(arg).addCustomFilter(filter, entityLogicaName)


  • filter: String. The fetchXml filter element to apply. For example:

    <filter type="and">
      <condition attribute="address1_city" operator="eq" value="Redmond" />
  • entityLogicalName: (Optional) String. If this is set, the filter only applies to that table type. Otherwise, it applies to all types of tables returned.


Unsure about entity vs. table? See Developers: Understand terminology in Microsoft Dataverse.


This method can only be used in a function in an event handler for the Lookup Control PreSearch Event.


The following code sample is for the Opportunity form Account (parentaccountid) lookup. When the Sdk.setParentAccountIdFilter function is set in the form Onload event handler, the Sdk.filterCustomAccounts function is added to the PreSearch event for that lookup. Remember to select the option to pass in the execution context when setting the function in the form Onload event handler. The result is that only accounts with the Category (accountcategorycode) value of Preferred Customer (1) will be returned.

// A namespace defined for SDK sample code
// You should define a unique namespace for your libraries
var Sdk = window.Sdk || {};

// set 'Sdk.setParentAccountIdFilter' in the Opportunity form onload event handler
Sdk.setParentAccountIdFilter = function (executionContext) {

    // get the form context
    formContext = executionContext.getFormContext();

Sdk.filterCustomerAccounts = function () {

    // Only show accounts with the type 'Preferred Customer'
    var customerAccountFilter = "<filter type='and'><condition attribute='accountcategorycode' operator='eq' value='1'/></filter>";
    formContext.getControl("parentaccountid").addCustomFilter(customerAccountFilter, "account");