Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.



Examples for including/excluding orders using basic filtering

This information applies to all Planned functions.

There are two methods for Filtering Orders

  1. OnSetFilter: Basic filtering using Header Fields (this article)
    • Works with both Standard and Custom header fields

  2. OnInclude: Complex per-document condition
    • Used for conditions that cannot be solved by OnSetFilter
    • Orders/Lines cannot be "re-included" once excluded via OnSetFilter-events. See How-to: Filter Orders - Complex


  • Help Text From Shared Block
    pageBusiness Central
    textClick to see event flow of getting orders.
  • Help Text From Shared Block
    textClick to view a guide to Headers.
  • Add your own fields to an existing header


Table of Contents

How to handle filters

Step 1 - Select the event

Select the correct event for the function area you are working on.

Content by Label
cqllabel = "bc" and label = "orders" and label = "onsetfilter" and label = "integrationevent" and ancestor = "47220743"


Step 2 - Structure your code

Make sure to affect all related documents if needed

Example: A change in filter "PO Number" should affect both:

  • "Warehouse Receipts"
  • "Purchase Orders"

Make your code callable from both events:

  • OnGetReceiveOrders_OnSetFilterPurchaseOrder

  • OnGetReceiveOrders_OnSetFilterWarehouseReceipt

Important note:

  • Line filters also affect Orders. If no Lines fits the filter, then the corresponding Order is excluded

Step 3 - Write your code

You are given these parameters to use for your filtering

titleClick to view parameters
  • _HeaderFilter.Name
  • _HeaderFilter.Value
    • The filter value collected from the mobile user
    • Use or Modify this value for filtering

  • _WhseReceiptHeader:
    • Resulting filtering set of Orders
    • Apply filters to affect the resulting OrderList

  • _WhseReceiptLine
    • Resulting filtering set of Order Lines
    • Apply filters to affect the resulting OrderList
      • Line filters also affects which Order are included
      • Empty lines = the order is not relevant
  • _IsHandled
    • Use this to decide whether the Standard code should continue to apply the filter as normal
    • You might want to Piggyback on a standard filter OR Overrule it


Note: The examples use Receive function, but works for all Planned Functions

Example 01: Modify "Location" filter

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt''', true, true)]
    procedure Example01_Additional_Location_Filtering(_HeaderFilter: Record "MOB NS Request Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _WhseReceiptLine: Record "Warehouse Receipt Line"; var _IsHandled: Boolean)
        // [Scenario]
        // Modify "Location" filter
        // Only if location is = "WHITE" OR "GREEN". Set filter to include Both Location, no matter which is chosen
        // Handle the filter, so standard filter is overruled

        if _HeaderFilter.Name = 'Location' then
            if _HeaderFilter."Value" IN ['WHITE''GREEN'then begin
                _WhseReceiptHeader.SetFilter("Location Code", '%1|%2''WHITE''GREEN');
                _IsHandled := true;

        // When Filter is NOT "White" or "Green", the standard code runs as normal and filters on the choosen location


Example 02: Modify "Expected Receipt Date" filter

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt''', true, true)]
    procedure Example02_Overrule_ExptRecptDate_Filter(_HeaderFilter: Record "MOB NS Request Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _WhseReceiptLine: Record "Warehouse Receipt Line"; var _IsHandled: Boolean)
        // [Scenario]
        // Receipt lines are default filtered for "Due Date" using the formula <=%1 where %1 is "Expected Receipt Date"
        // Overrule the filter to always search one year forward from the current workdate

        // Filter on LINES will also affect which ORDERS that are included

        if _HeaderFilter.Name = 'Date' then begin
            _WhseReceiptLine.SetFilter("Due Date", '..%1', CalcDate('<CY+1Y>', WorkDate()));         // Filter on LINES will also affect which ORDERS that are included  // One year from the current workdate
            _IsHandled := true;

Example 03: Modify "Purchase Order" filter

   [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt''', true, true)]
    procedure Example03_Validate_PurchaseOrder_Filter(_HeaderFilter: Record "MOB NS Request Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _WhseReceiptLine: Record "Warehouse Receipt Line"; var _IsHandled: Boolean)
        PurchaseHeader: Record "Purchase Header";
        // [Scenario]
        // Add validation to the "Purchase Order" filter by checking the order is Open
        // If not, abort process and force user to change filter

        if _HeaderFilter.Name = 'PurchaseOrderNumber' then
            if PurchaseHeader.Get(PurchaseHeader."Document Type"::"Order", _HeaderFilter."Value") and (PurchaseHeader.Status <> PurchaseHeader.Status::Releasedthen
                Error('Purchase Order %1 is not released', PurchaseHeader."No.")// We use "error" since filter a single document no. (Error is not recommended for common filtering)

        // _IsHandled: No point in handling the filter or not, as Error stops the entire proces if needed


Example 04: Modify "Assigned User" filter

    [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt''', true, true)]
    procedure Example04_Overrule_AssignedUserAll_Filter(_HeaderFilter: Record "MOB NS Request Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _WhseReceiptLine: Record "Warehouse Receipt Line"; var _IsHandled: Boolean)
        // [Scenario]
        // Overrule when the standard filter "Assigned User" is set to "All"
        // Instead of no filter, set a filter that must not be Blank
        // Handle the filter, so standard filter is overruled

        if _HeaderFilter.Name = 'AssignedUser' then
            if _HeaderFilter."Value" = 'All' then begin
                _WhseReceiptHeader.SetFilter("Assigned User ID", '<>%1''');  // Order must be assigned to someone
                _IsHandled := true;

Example 05: Modify "ScannedValue" filter

   [EventSubscriber(ObjectType::CodeunitCodeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt''', true, true)]
    procedure Example05_Validate_ScannedValue_Filter(_HeaderFilter: Record "MOB NS Request Element"; var _WhseReceiptHeader: Record "Warehouse Receipt Header"; var _WhseReceiptLine: Record "Warehouse Receipt Line"; var _IsHandled: Boolean)
        // [Scenario]
        // Overrule when the standard filter "Scanned Value"

        // Instead of searching for Item No., use the value to filter Document no.
        // Handle the filter, so standard filter is overruled

        if _HeaderFilter.Name = 'ScannedValue' then begin
            _WhseReceiptHeader.SetRange("No.", _HeaderFilter."Value");
            _IsHandled := true;


Receive Order filters

Press the filter icon to show the header filter

Put-away Order filter

Pick Order filter