该方法 addCustomFilter 将筛选器添加到模型驱动应用中查找控件中显示的结果。 每个筛选器与以前添加的任何筛选器合并为条件 AND 。
支持的控件类型
查找
Syntax
formContext.getControl(arg).addCustomFilter(filter, entityLogicalName)
参数
| Name | 类型 | Description |
|---|---|---|
filter |
String | 要应用的 FetchXML 筛选器元素。 |
entityLogicalName |
String | Optional. 如果设置此参数,筛选器仅适用于该表类型。 否则,它适用于返回的所有类型的表。 |
例如,将以下 XML 用于 filter 参数:
<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>
注解
在 查找控件 PreSearch 事件的事件处理程序中的函数中使用此方法。
Example
下面的代码示例适用于 “机会 ”窗体 帐户 (parentaccountid)查找。 在表单Onload事件处理程序中设置Sdk.setParentAccountIdFilter函数时,请将Sdk.filterCustomerAccounts该函数添加到该PreSearch查找的事件。 请记住,选择在窗体 Onload 事件处理程序中设置函数时传入执行上下文的选项。 结果是只返回“首选客户”(accountcategorycode1)类别值(1)的帐户。
// A namespace defined for SDK sample code
// You should define a unique namespace for your libraries
const Sdk = (window.Sdk ??= {});
// set 'Sdk.setParentAccountIdFilter' in the Opportunity form onload event handler
Sdk.setParentAccountIdFilter = (executionContext) => {
const formContext = executionContext.getFormContext();
formContext.getControl("parentaccountid").addPreSearch(Sdk.filterCustomerAccounts);
};
Sdk.filterCustomerAccounts = (executionContext) => {
const control = executionContext.getEventSource();
const customerAccountFilter = `
<filter type="and">
<condition attribute="accountcategorycode" operator="eq" value="1" />
</filter>`;
control.addCustomFilter(customerAccountFilter, "account");
};