- Created by Johannes Sebastian Nielsen, last modified on Mar 13, 2023
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 170 Next »
Description
Examples for including/excluding orders using basic filtering
There are two methods for Filtering Orders
- OnSetFilter: Basic filtering using Header Fields (this article)
- Works with both Standard and Custom header fields
- Works with both Standard and Custom header fields
- 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
Tips
Add your own custom fields to an existing header
These examples focus on existing fields, but you can also add your own custom fields to an existing header.
See OnGetReferenceData_OnAddHeaderConfigurations
Examples
How to handle filters
Step 1 - Select the event
Select the correct event for the function area you are working on.
Filter by label
There are no items with the selected labels at this time.
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
- _HeaderFilter.Name
- Name of filter
- I.e.: 'AssignedUser', 'ScannedValue', 'Location' etc.
- Or custom name given in OnGetReferenceData_OnAddHeaderConfigurations
- Use this to check if the event handling your desired filter
- Name of filter
- _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
Examples
Note: The examples use Receive function, but works for all Planned Functions
Example 01: Modify "Location" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"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)
begin
// [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;
end;
// When Filter is NOT "White" or "Green", the standard code runs as normal and filters on the choosen location
end;
Example 02: Modify "Expected Receipt Date" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"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)
begin
// [Scenario]
// Add additional "Due Date" filter to the standard "Expected Receipt Date" filter on Receipt Lines
// Note: A filter on LINES will also affect which Orders are included
// Handle the filter, so standard filter is overruled
if _HeaderFilter.Name = 'Date' then begin
// We use a "static" filter, not the dynamic "_HeaderFilter.Value" from the user
// Filter due date 1 year higher than current year
_WhseReceiptLine.SetFilter("Due Date", '..%1', CalcDate('<CY+1Y>', WorkDate()));
_IsHandled := true;
end;
end;
Example 03: Modify "Purchase Order" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"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)
var
PurchaseHeader: Record "Purchase Header";
begin
// [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::Released) then
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
end;
Example 04: Modify "Assigned User" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"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)
begin
// [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;
end;
end;
Example 05: Modify "ScannedValue" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"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)
begin
// [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;
end;
end;
Receive Order filters
Press the filter icon to show the header filter
Put-away Order filter
Pick Order filter
- No labels