Skip to content

[Event Request] codeunit 5979 "Service-Post and Send" - OnBeforConfirmPostAndSend - OnBeforePost #30420

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an eventext-ready-to-implementReviewed and ready to implement and create PR

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions