addCustomFilter メソッドは、モデル駆動型アプリのルックアップ コントロールに表示される結果にフィルターを追加します。 各フィルターは、 AND 条件として以前に追加されたフィルターと組み合わされます。
サポートされているコントロールの種類
参照
構文
formContext.getControl(arg).addCustomFilter(filter, entityLogicalName)
パラメーター
| 名前 | タイプ | Description |
|---|---|---|
filter |
String | 適用する FetchXML フィルター要素。 |
entityLogicalName |
String | Optional. このパラメーターを設定した場合、フィルターはそのテーブルの種類にのみ適用されます。 それ以外の場合は、返されたテーブルのすべてのタイプに適用されます。 |
たとえば、 filter パラメーターには次の XML を使用します。
<filter type="and">
<condition attribute="address1_city" operator="eq" value="Redmond" />
</filter>
備考
このメソッドは、 Lookup Control PreSearch イベントのイベント ハンドラーの関数で使用します。
例
次のコード サンプルは、 営業案件 フォーム の取引先 企業 (parentaccountid) 参照用です。 フォーム Onload イベント ハンドラーでSdk.setParentAccountIdFilter関数を設定する場合は、その参照のPreSearch イベントにSdk.filterCustomerAccounts関数を追加します。 イベント ハンドラーのフォームで関数を設定するときに、実行コンテキストで渡すオプション Onload 必ず選択してください。 結果として、優先顧客 (1) のカテゴリ (accountcategorycode) 値を持つアカウントのみが返されます。
// 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");
};