共用方式為


addCustomFilter (用戶端 API 參考)

將篩選器新增至查閱中顯示的結果。 每個篩選器都會與任何先前新增的篩選器結合做為 AND 條件。

支援的控制項類型

查詢

語法

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

參數

  • filter:字串。 要套用的 fetchXml 篩選元素。 例如:

    <filter type="and">
      <condition attribute="address1_city" operator="eq" value="Redmond" />
    </filter>
    
  • entityLogicalName:(選擇性)字串。 如果設定此選項,則過濾器僅適用於該表格類型。 否則,它會套用至傳回的所有資料表類型。

備註

這個方法只能用於 查閱控制項預先搜尋事件的事件處理常式中的函式中。

Example

下列程式碼範例適用於 Opportunity 表單 Account (parentaccountid) 查閱。 在表單 Onload 事件處理常式中設定 Sdk.setParentAccountIdFilter 函式時,Sdk.filterCustomAccounts 函式會新增至該查閱的 PreSearch 事件。 請記得在表單 Onload 事件處理常式中設定函式時,選取要傳入執行內容的選項。 結果是,只會傳回 類別 ( accountcategorycode) 值為 Preferred Customer (1) 的帳戶。

// 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