Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Description
Excerpt |
---|
Examples for including/excluding orders using basic filtering |
This information applies to all Planned functions.
There are two methods for filtering orders
- OnSetFilter: Basic filter (this article)
- Works with both standard and custom Header-fields
- Works with both standard and custom Header-fields
- OnInclude: Complex per-document filter
- Used for conditions that cannot be solved by OnSetFilter.
- Elements cannot be "re-included" once excluded via OnSetFilter-events
- See How-to: Filter Orders - Complex
See also
Expand | ||
---|---|---|
| ||
See more: Planned Functions |
Adding fields to an existing headerSee also Use Headers
Examples
Table of Contents | ||||||
---|---|---|---|---|---|---|
|
How to handle filters
Step 1 - Select the event
Select the correct event for the function area you are working on.
Filter by label (Content by label) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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
Expand | ||
---|---|---|
| ||
|
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)]
local 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)]
local 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]
// 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 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())); // One year from the current workdate
_IsHandled := true;
end;
end;
Example 03: Modify "Purchase Order" filter
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt', '', true, true)]
local 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)
local 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
If you are scanning an Encoded Barcode (GS1) then you have to update the"orderFilterGs1AI" on Planned (Service) Mobile Configuration.
See Select Order by scan (scannedValue) for details.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"MOB WMS Receive", 'OnGetReceiveOrders_OnSetFilterWarehouseReceipt', '', true, true)]
local 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