Versions Compared

Key

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

Description

Excerpt

You may subscribe to posting events in the Business Central base App to process collected values, or when events offered by Extension API does not fit your exact need.

...

Note
titleCommit

Common for MOB OnHandleRegistrationFor[...] and OnBeforePosting[...] events is database transactions on these events is committed to the database prior to calling the standard posting functions.

  • This requires your code to be structured to take into account that your database transaction will not be rolled back on error
 during standard posting.
  • during standard posting.

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



When subscribing to standard events

...

TODO  Verify sample code

[EventSubscriber(ObjectType::CodeunitCodeunit::"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;