แชร์ผ่าน


addCustomFilter (การอ้างอิง API ไคลเอ็นต์)

เพิ่มตัวกรองไปยังผลลัพธ์ที่แสดงในการค้นหา ตัวกรองแต่ละตัวจะถูกรวมเข้ากับตัวกรองใด ๆ ที่เพิ่มไว้ก่อนหน้านี้เป็น AND เงื่อนไข

ประเภทตัวควบคุมที่ได้รับการสนับสนุน

การค้นหา

ไวยากรณ์

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

พารามิเตอร์

  • filter: สตริง องค์ประกอบตัวกรอง fetchXml ที่จะนําไปใช้ เช่น:

    <filter type="and">
      <condition attribute="address1_city" operator="eq" value="Redmond" />
    </filter>
    
  • entityLogicalName: สตริง (ไม่บังคับ) ถ้าตั้งค่านี้ ตัวกรองจะใช้กับชนิดตารางนั้นเท่านั้น มิฉะนั้นจะนําไปใช้กับตารางทุกประเภทที่ส่งกลับ

หมายเหตุ

เมธอดนี้สามารถใช้ได้เฉพาะในฟังก์ชันในตัวจัดการเหตุการณ์สําหรับเหตุการณ์ Lookup Control PreSearch

ตัวอย่าง

ตัวอย่างรหัสต่อไปนี้มีไว้สําหรับการค้นหา บัญชีฟอร์ม โอกาส (parentaccountid) เมื่อตั้งค่าฟังก์ชัน Sdk.setParentAccountIdFilter ในตัวจัดการเหตุการณ์ Onload ของฟอร์ม ฟังก์ชัน Sdk.filterCustomAccounts จะถูกเพิ่มไปยังเหตุการณ์ PreSearch สําหรับการค้นหานั้น อย่าลืมเลือกตัวเลือกที่จะส่งผ่านในบริบทการดําเนินการเมื่อตั้งค่าฟังก์ชันในตัวจัดการเหตุการณ์ Onload ของฟอร์ม ผลลัพธ์คือ ระบบจะแสดงเฉพาะบัญชีที่มีค่า ประเภท (accountcategorycode) ของลูกค้าที่ต้องการ (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