Description
...
- Move "staged" data to the final destination during posting.
- Process a workflow during posting that requires your data to be rolled back on error.
- Process a workflow on after posting that is not required to be a part of same database transaction or is not sensitive to not being fully executed in case of error (ie. printing labels).
Event flow overview
...
- .
...
1) Define Steps
Events:
- Header Steps = OnGetReceiveOrderLines_OnAddStepsToAnyHeader
- Line Steps = OnGetReceiveOrderLines_OnAddStepsToAnyLine
2) Handle collected Step values (I.e. Commit data to staging tables)
Events:
- Header Steps = OnPostReceiveOrder_OnBeforePost...
- Line Steps = OnPostReceiveOrder_OnHandleRegistrationFor...
3) Standard posting event (I.e. Use and Clean-up data from staging tables)
Event:
- Codeunit::"Whse.-Post Receipt", 'OnBeforePostSourceDocument'
Note | ||
---|---|---|
| ||
Common for MOB Database transactions in OnHandleRegistrationFor[...] and OnBeforePosting[...] events is database transactions on these events is committed to the database are committed prior to calling the standard posting functions.
Preferably your code should be organized to "stage" collected values in a manner that will allow standard posting events to access the collected values, yet takes into account that posting may never complete or data may change prior to next posting.
|
...
Carefully choose which standard BC events you subscribe to, and give ample consideration to how Commits in standard posting codeunits will affect your code and data being rolled back correctly.
- Preferably your code should be organized to "stage" collected values in a manner that will allow standard posting events to access the collected values, yet takes into account that posting may never complete or data may change prior to next posting.
...
- Your EventSubscriber is "triggered" when posting from Mobile Device or
- Subscribing to MOB events "OnBeforePost[...]" and "OnHandleRegistrationFor[...]" is the recommended way of "staging" data prior to posting
You have two clients to consider
- Remember, your Events are fired both when posting from the Mobile Device, the Mobile Document Queue, but also when posting from Web Client (including for documents not associated with Mobile WMS).
- So your code must allow execution both when triggered from Mobile WMS, and when triggered from Web Client.
- So your code must allow execution both when triggered from Mobile WMS, and when triggered from Web Client.
- The document header field "MOB Posting MessageId" is populated when posting a document from Mobile or Queue but not when posting from Web Client.
- When document header field "MOB Posting MessageId" is empty the Mobile Message cannot be accessed from your posting context and only "staged" collected values from a previous try can be accessed.
- Re-trying from the Web Client will not populate "MOB Posting MessageId".
- However, "staged" data that is is committed will will be available/visible when posting re-trying from Web Client.
- Preferably your code should be organized to "stage" collected values in a manner that will allow standard posting events to access the collected values, yet takes into account that posting may never complete or data may change prior to next posting.
- Subscribing to MOB events "OnBeforePost[...]" and "OnHandleRegistrationFor[...]" is the recommended way of "staging" data prior to posting
Event flow overview
In step 3 you need to decide whether to subscribe to standard posting events.
1) Define Steps
Define which Steps to collect
Events:
- Header Steps = OnGetReceiveOrderLines_OnAddStepsToAnyHeader
- Line Steps = OnGetReceiveOrderLines_OnAddStepsToAnyLine
2) Handle collected Step values
Stage collected date in custom tables/fields
Events:
- Header Steps = OnPostReceiveOrder_OnBeforePost...
- Line Steps = OnPostReceiveOrder_OnHandleRegistrationFor...
3) Standard posting occurs
Post and Clean-up staged data
Event:
- Codeunit::"Whse.-Post Receipt", 'OnBeforePostSourceDocument'
Example
TODO Verify sample code
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Sales-Post", 'OnRunOnBeforeFinalizePosting', '', false, false)]
local procedure MyOnPostingSalesReturnOrder_OnRunOnBeforeFinalizePosting(var SalesHeader: Record "Sales Header"; var SalesShipmentHeader: Record "Sales Shipment Header"; var SalesInvoiceHeader: Record "Sales Invoice Header"; var SalesCrMemoHeader: Record "Sales Cr.Memo Header"; var ReturnReceiptHeader: Record "Return Receipt Header"; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; CommitIsSuppressed: Boolean)
var
OrderValues: Record "MOB Common Element" temporary;
MobRequestMgt: Codeunit "MOB NS Request Management";
HeaderRecRef: RecordRef;
begin
if IsNullGuid(SalesHeader."MOB Posting MessageId") then
exit; // not Mobile WMS posting or retry from Web Client
if (SalesHeader."Document Type" = SalesHeader."Document Type"::"Return Order") and (ReturnReceiptHeader."No." <> '') then begin
HeaderRecRef.GetTable(SalesHeader);
MobRequestMgt.GetOrderValues(SalesHeader."MOB Posting MessageId", OrderValues);
MyOnPostReceiveOrder_OnPostingSalesReturnOrder(OrderValues, SalesHeader, ReturnReceiptHeader);
end;
end;