microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
732 stars 243 forks source link

Microsoft_Statistical Accounts_22.5.59966.60187 : Codeunit 2624 : Stat. Acc. Jnl. Line Post #7548

Closed ClintonSaundersSeeSide closed 11 months ago

ClintonSaundersSeeSide commented 11 months ago

Please include the following with each issue:

1. Describe the bug When writing extensions that run the above codeunit (and therefor executing the OnRun trigger), a "Record already exists in the Statistical Ledger Entry table". The normal posting routine that starts with Codeunit 2626 : Stat. Acc. Post. Batch does not produce the same error because it does not use the OnRun trigger in codeunit 2624.

2. To Reproduce Write code to populate the "Statistical Acc. Journal Line" table, then run codeunit 2624 and passing the newly created Journal Line.

  1. Go to '...'
        StatsJnlLine.Init();
        StatsJnlLine."Document No." := GenJnlLine."Document No.";
        StatsJnlLine."Posting Date" := GenJnlLine."Posting Date";
        StatsJnlLine.Description := StrSubstNo(DescrTxt, VendLedgEntry."Policy No.");
        StatsJnlLine.Amount := AppliedAmount;
        StatsJnlLine."Shortcut Dimension 1 Code" := VendLedgEntry."Global Dimension 1 Code";
        StatsJnlLine."Shortcut Dimension 2 Code" := VendLedgEntry."Global Dimension 2 Code";
        StatsJnlLine."Dimension Set ID" := VendLedgEntry."Dimension Set ID";
        StatsJnlLine.Insert();

        Codeunit.Run(Codeunit::"Statistical Jnl. Post Line", StatsJnlLine);
        StatsJnlLine.Delete();

I believe the problem is in Function "internal procedure PostLine(var StatisticalAccJournalLine: Record "Statistical Acc. Journal Line"; var NextEntryNo: Integer; TransactionNumber: Integer)", specifically the following two lines:

        StatisticalLedgerEntry."Entry No." := NextEntryNo;
        NextEntryNo += 1;

I believe that the problem will be resolved if these two lines are swapped around.

Note: Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.

3. Expected behavior A new Statistical Ledger Entry should be created

4. Actual behavior A "Record Already exists in the Statistical Ledger Entry Table" is produced, becauase the system tries to use the last Entry No. in the Statistical Ledger Entry table as the Entry No for the new entry.

5. Versions:

Final Checklist

Please remember to do the following:

EmilDamsbo commented 11 months ago

Let's get the issue to a team who will fix and backport it, as this repository is only for issues related to the AL compiler in latest developer preview environment for Dynamics 365 Business Central. We suggest that you open a support case or file a bug in Collaborate, to ensure that all Business Central users benefit from your catch as soon as possible.

To open a support case, you can:

If you file the bug in Collaborate, remember to include steps to reproduce the issue, and the Business Central build number and country version you're using.