[Event Request] codeunit 5979 "Service-Post and Send" - OnBeforConfirmPostAndSend - OnBeforePost
Why do you need this change?
I need this change to be able to use Service post and Send for Service Header document type Order.
Describe the request
Describe the request
Hello, I was wondering if we could get two events in Codeunit 5979 "Service-Post and Send" ΓÇö OnBeforeConfirmPostAndSend and OnBeforePost?
Today the Code() procedure hard-codes the supported document types (only Invoice and Credit Memo) and calls Service-Post directly, so there is no way to support posting a Service Order from Post & Send, or to substitute the posting routine, without copying the whole codeunit. These two events would let us do that from a subscriber.
Location in the Code() procedure:
local procedure "Code"()
var
TempDocumentSendingProfile: Record "Document Sending Profile" temporary;
ServicePost: Codeunit "Service-Post";
//>>>>>>>>>>>>>>>>>>>>>>>>>
IsHandled: Boolean;
SkipPost: Boolean;
//<<<<<<<<<<<<<<<<<<<<<<<<<
begin
OnBeforeCode(ServiceHeader);
//>>>>>>>>>>>>>>>>>>>>>>>>>
IsHandled := false;
OnBeforeConfirmPostAndSend(ServiceHeader, IsHandled);
if IsHandled then begin
if not ConfirmPostAndSend(ServiceHeader, TempDocumentSendingProfile) then
exit;
end else
//<<<<<<<<<<<<<<<<<<<<<<<<<
case ServiceHeader."Document Type" of
ServiceHeader."Document Type"::Invoice,
ServiceHeader."Document Type"::"Credit Memo":
if not ConfirmPostAndSend(ServiceHeader, TempDocumentSendingProfile) then
exit;
else
Error(NotSupportedDocumentTypeErr, ServiceHeader."Document Type");
end;
TempDocumentSendingProfile.CheckElectronicSendingEnabled();
ValidateElectronicFormats(TempDocumentSendingProfile);
//>>>>>>>>>>>>>>>>>>>>>>>>>
IsHandled := false;
SkipPost := false;
OnBeforePost(ServiceHeader, IsHandled, SkipPost);
if IsHandled then begin
if SkipPost then
exit;
end else
//<<<<<<<<<<<<<<<<<<<<<<<<<
CODEUNIT.Run(CODEUNIT::"Service-Post", ServiceHeader);
OnAfterPostAndBeforeSend(ServiceHeader);
Commit();
ServicePost.SendPostedDocumentRecord(ServiceHeader, TempDocumentSendingProfile);
OnAfterCode(ServiceHeader);
end;
Event publishers:
[IntegrationEvent(false, false)]
local procedure OnBeforeConfirmPostAndSend(var ServiceHeader: Record "Service Header"; var IsHandled: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnBeforePost(var ServiceHeader: Record "Service Header"; var IsHandled: Boolean; var SkipPost: Boolean)
begin
end;
With OnBeforeConfirmPostAndSend, a subscriber can accept additional document types (e.g. Order) by setting IsHandled, which runs ConfirmPostAndSend and skips the else Error. With OnBeforePost, a subscriber can replace the posting (e.g. the Ship/Consume/Invoice dialog for Orders) via IsHandled, and use SkipPost to stop before SendPostedDocumentRecord when nothing was posted.
Internal work item: AB#648196
Hi @AlaAuz,
Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.
Missing Information:
- Performance considerations: Please add a brief statement about the expected execution frequency of these new IsHandled events and their anticipated performance impact.
- Data sensitivity review: Please confirm that the requested events do not expose sensitive data, or explain the sensitivity implications if they do.
- Multi-extension interaction: Please acknowledge the risk of multiple extensions subscribing to these events and briefly explain how that risk is acceptable or should be mitigated.
Please update the issue with the missing details. We'll automatically re-analyze once updated.
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Not accurate? Reply with
/not-accurate(optional: add a short explanation). Your feedback improves future responses.
Performance considerations
The events are executed only once per invocation of Codeunit 5979, during the Post & Send process. They are lightweight integration events with no additional processing in the standard implementation. The performance impact is therefore expected to be negligible. Subscribers should, as usual, avoid expensive operations or unnecessary database queries unless required for their specific scenario.
Data sensitivity review
These events expose the Service Header record, which contains the information already available to code executing within the Service Post & Send process. They do not introduce access to a new data source or expose credentials, authentication information, or other inherently sensitive system data. Extensions subscribing to the events should follow the normal Business Central data-access and permission model when handling Service Header data.
Multi-extension interaction
We acknowledge that multiple extensions may subscribe to these events and potentially modify the IsHandled/SkipPost parameters. This is an accepted pattern for Business Central integration events, but subscribers should use these parameters carefully and only handle scenarios they explicitly support. In particular, subscribers should check the document type and exit when the event is not relevant to them, as in the proposed implementation. This minimizes interference between extensions and allows multiple extensions to coexist.
Hi @AlaAuz,
Thank you for your extensibility request. To help us process it efficiently, please update the issue to include the required information.
Missing Information:
- Critical posting replacement handling: Please confirm that you understand
OnBeforePost(var ServiceHeader, var IsHandled, var SkipPost)can bypass the standardService-Postroutine, and explain how your extension will safely replace that posting logic. - Posted-document/send coordination: Please explain how your implementation will ensure
SkipPostis set only when no posted document exists, soSendPostedDocumentRecordis not reached in an invalid state.
Please update the issue with the missing details. We'll automatically re-analyze once updated.
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Not accurate? Reply with
/not-accurate(optional: add a short explanation). Your feedback improves future responses.
Critical posting replacement handling I understand that OnBeforePost(var ServiceHeader, var IsHandled, var SkipPost) allows an extension to bypass the standard Service-Post codeunit by setting IsHandled := true.
Our intended use case is to support Service Header document type Order, where the standard Service-Post flow is not sufficient for our business process. In the subscriber, we would take responsibility for the complete posting operation, including all required validation and posting logic, and ensure that the appropriate posted document is created before the flow continues to the sending logic.
We would only set IsHandled := true when our subscriber has explicitly taken over the posting operation. We understand that doing so means the extension is responsible for maintaining the expected posting state and for ensuring that the standard posting routine is not also executed.
Posted-document/send coordination We also understand the purpose of SkipPost.
Our subscriber would set SkipPost := true only when it intentionally handles the flow without creating a posted document and therefore the subsequent SendPostedDocumentRecord(ServiceHeader, TempDocumentSendingProfile) call must not be reached.
If our replacement posting logic successfully creates the expected posted document, SkipPost would remain false, allowing the existing flow to continue to OnAfterPostAndBeforeSend, Commit(), and SendPostedDocumentRecord.
In other words, the extension will ensure that SendPostedDocumentRecord is only reached when the posting operation has produced the appropriate posted document/state expected by the sending logic. We will not use SkipPost merely to suppress an error or to bypass posting while still allowing the standard send operation to execute.
The proposed events are intended to provide a supported extension point for this scenario rather than requiring a copy of the entire Service-Post and Send codeunit.
✅ Analysis complete - ready for further processing
Implementation:
Add OnCodeOnBeforeConfirmPostAndSend before the hard-coded document type validation in Code() and OnCodeOnBeforePost before the standard Service-Post execution so extensions can allow additional document types and optionally take over posting.
Location in Code() procedure:
local procedure "Code"()
var
TempDocumentSendingProfile: Record "Document Sending Profile" temporary;
ServicePost: Codeunit "Service-Post";
ConfirmPostAndSendIsHandled: Boolean; // NEW
PostIsHandled: Boolean; // NEW
SkipPost: Boolean; // NEW
begin
OnBeforeCode(ServiceHeader);
ConfirmPostAndSendIsHandled := false; // NEW
OnCodeOnBeforeConfirmPostAndSend(ServiceHeader, ConfirmPostAndSendIsHandled); // NEW
if ConfirmPostAndSendIsHandled or // NEW
(ServiceHeader."Document Type" in [ServiceHeader."Document Type"::Invoice, ServiceHeader."Document Type"::"Credit Memo"]) // NEW
then begin
if not ConfirmPostAndSend(ServiceHeader, TempDocumentSendingProfile) then
exit;
end else
Error(NotSupportedDocumentTypeErr, ServiceHeader."Document Type");
TempDocumentSendingProfile.CheckElectronicSendingEnabled();
ValidateElectronicFormats(TempDocumentSendingProfile);
PostIsHandled := false; // NEW
SkipPost := false; // NEW
OnCodeOnBeforePost(ServiceHeader, PostIsHandled, SkipPost); // NEW
if not PostIsHandled then // NEW
CODEUNIT.Run(CODEUNIT::"Service-Post", ServiceHeader);
if SkipPost then // NEW
exit; // NEW
OnAfterPostAndBeforeSend(ServiceHeader);
Commit();
ServicePost.SendPostedDocumentRecord(ServiceHeader, TempDocumentSendingProfile);
OnAfterCode(ServiceHeader);
end;
Event Publisher (add at the end of the codeunit with other events):
[IntegrationEvent(false, false)]
local procedure OnCodeOnBeforeConfirmPostAndSend(var ServiceHeader: Record "Service Header"; var IsHandled: Boolean)
begin
end;
[IntegrationEvent(false, false)]
local procedure OnCodeOnBeforePost(var ServiceHeader: Record "Service Header"; var IsHandled: Boolean; var SkipPost: Boolean)
begin
end;
File: ServicePostandSend.Codeunit.al
[!NOTE] Automatically generated by the Triage Agent — advisory only. An engineer will review before any action is taken.
[!TIP] Not accurate? Reply with
/not-accurate(optional: add a short explanation). Your feedback improves future responses.
There is an active PR for this issue https://github.com/microsoft/BCApps/pull/10992 It will be completed in next period.
As this repo will be archived in few days, closing the issue. Please track progress on the PR