- Created by Johannes Sebastian Nielsen, last modified on Oct 19, 2023
You are viewing an old version of this page. View the current version.
Compare with Current View Page History
« Previous Version 184 Next »
Description
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
- ...OnSetFilter-events
- Reads data from source tables
- Add Filters
- Modify Filters
- Reads data from source tables
- ...OnAfterSetFrom-events
- Data goes into accessor table "BaseOrderLineElement"
- Add Data
- Modify Data
- Set Sorting Key Fields (Custom fields)
- Data goes into accessor table "BaseOrderLineElement"
- ...OnAfterSetCurrentKey-events
- Data is sorted
- Set Sorting Key Fields (ONLY standard fields)
- Set Sorting Direction
- Data is sorted
- (XML Response is transmitted to the Mobile Device)
See more: Planned Functions
Adding fields to an existing header
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]
// 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)]
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