Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BC Idea]: Correct commit and error handling in codeunit Gen. Jnl.-Post Line OnAfterGLFinishPosting event #2192

Open
1 task done
ernestasjuska opened this issue Oct 14, 2024 · 1 comment
Labels
BCIdea Issue related to a BCIdea Finance GitHub request for Finance area Follow Up The issue has an open question and must be followed up on Linked Issue is linked to a Azure Boards work item

Comments

@ernestasjuska
Copy link

ernestasjuska commented Oct 14, 2024

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=5c4328ef-218a-ef11-9442-6045bdbf4815

Description

Hi,

The general journal lines are only deleted after posting the batch. But the events from the codeunit Gen. Jnl.-Post Line allow commit before the posting ends. This means after a commit and then an error in the event subscriber, both posted entry and journal line remain in database.

For example, we stumbled upon a rare case when codeunit "CustEntry-Apply Posted Entries" calls codeunit "Payment Tolerance Management" that did a commit and then codeunit "CustEntry-Apply Posted Entries" showed an error.

To reproduce the issue, create a new app with an event subscriber like this:

codeunit 50100 "BREAK Event Subscribers"
{
    InherentPermissions = X;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", OnAfterGLFinishPosting, '', false, false)]
    local procedure "Gen. Jnl.-Post Line_OnAfterGLFinishPosting"()
    begin
        Commit();
        Error('err');
    end;
}

PostingProblemApp.zip

Posting a payment to customer using payments journal will show error message 'err'. The customer ledger entry will be created even though there was an error.

Please add attribute [CommitBehavior(CommitBehavior::Ignore)] on codeunit Gen. Jnl.-Post Line OnAfterGLFinishPosting event publisher.

Thanks.

Example correction - to demonstrate that it works (it can handle "if codeunit.run then"):

codeunit 50100 "BREAK Event Subscribers"
{
    InherentPermissions = X;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Gen. Jnl.-Post Line", OnAfterGLFinishPosting, '', false, false)]
    local procedure "Gen. Jnl.-Post Line_OnAfterGLFinishPosting"()
    begin
        OnFixedEvent();
    end;

    [IntegrationEvent(false, false)]
    [CommitBehavior(CommitBehavior::Ignore)] // NOTE: Add this to OnAfterGLFinishPosting
    local procedure OnFixedEvent()
    begin
    end;

    [EventSubscriber(ObjectType::Codeunit, Codeunit::"BREAK Event Subscribers", OnFixedEvent, '', false, false)]
    local procedure HandleOnFixedEvent()
    begin
        Commit();
        Error('err');
    end;
}

In general, I don't expect commits when using Gen. Jnl.-Post Line. So the attribute could be lifted to procedure Code().

I will provide the implementation for this BC Idea

  • I will provide the implementation for this BC Idea
 codeunit 12 "Gen. Jnl.-Post Line"
 {
     // ...
 
     [IntegrationEvent(false, false)]
+    [CommitBehavior(CommitBehavior::Ignore)]
     local procedure OnAfterGLFinishPosting(GLEntry: Record "G/L Entry"; var GenJnlLine: Record "Gen. Journal Line"; var IsTransactionConsistent: Boolean; FirstTransactionNo: Integer; var GLRegister: Record "G/L Register"; var TempGLEntryBuf: Record "G/L Entry" temporary; var NextEntryNo: Integer; var NextTransactionNo: Integer)
     begin
     end;
 
     // ...
 }

Internal work item: AB#555074

@ernestasjuska ernestasjuska added the BCIdea Issue related to a BCIdea label Oct 14, 2024
@bcbuild-github-agent bcbuild-github-agent added the Linked Issue is linked to a Azure Boards work item label Oct 17, 2024
@t-prda t-prda added the Finance GitHub request for Finance area label Oct 17, 2024
@JesperSchulz
Copy link
Contributor

Sounds fair, but since the code you are referring to is in the BaseApp, you'd have to suggest and fix this code in the BaseApp contribution pilot: https://github.com/microsoft/businesscentralapps. For access to the pilot, please fill out the following form: https://forms.office.com/r/E9wyE5a58f.

Would you like me to move the issue to the contribution pilot for you?

IMPORTANT: Microsoft is not going to address the reported issue for you. You will have to get the issue approved, and then push a pull request with the suggested changes yourself. If you would like Microsoft to address the issue, please create a support request. Learn more about our support channels here: https://aka.ms/bcsupport.

@JesperSchulz JesperSchulz added the Follow Up The issue has an open question and must be followed up on label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BCIdea Issue related to a BCIdea Finance GitHub request for Finance area Follow Up The issue has an open question and must be followed up on Linked Issue is linked to a Azure Boards work item
Projects
None yet
Development

No branches or pull requests

4 participants