addCustomFilter (客户端 API 参考)

将筛选器添加到查找中显示的结果。 每个筛选器将与以前添加的任何筛选器合并为一个 AND 条件。

支持的控件类型

查找

Syntax

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

参数

  • filter:String。 要应用的 fetchXml 筛选器元素。 例如:

    <filter type="and">
      <condition attribute="address1_city" operator="eq" value="Redmond" />
    </filter>
    
  • entityLogicalName:(可选)字符串。 如果已设置,筛选器仅适用于该表类型。 否则,它适用于返回的所有类型的表。

注解

此方法只能在 查找控件 PreSearch 事件的事件处理程序中的函数中使用。

Example

下面的代码示例适用于“机会”表单 帐户 (parentaccountid)查找。 在 Onload 事件处理程序中设置 Sdk.setParentAccountIdFilter 函数时,Sdk.filterCustomAccounts 函数将添加到 PreSearch 事件以供查找。 请记住,选择在 Onload 事件处理程序中设置函数时传入执行上下文的选项。 结果是仅返回具有 Preferred Customer (1) 的 Category (accountcategorycode) 值的帐户。

// 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();
    formContext.getControl("parentaccountid").addPreSearch(Sdk.filterCustomerAccounts);
}

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

addPreSearch
formContext