Quantcast
Viewing all articles
Browse latest Browse all 64865

Blog Post: The G/L Entry already exists error message in Dynamics NAV 2013

The G/L Entry already exists error message in Microsoft Dynamics NAV 2013

I recently encountered an issue while posting an item journal line for a serialized item. This was a situation where the Quantity > 1, one serial number per quantity entered in Item Tracking, and the Job No. and Job Task No. fields were both populated on the item journal line.

Image may be NSFW.
Clik here to view.
"G/L Entry already exists" error message in NAV 2013

Resolution

To resolve the problem required a modification in object Codeunit 22, Item Jnl.-Post Line. The code snippet below shows before and after the modification:

OBJECT Codeunit 22 Item Jnl.-Post Line***************** BEFORE *************************************************************************    LOCAL PROCEDURE PostInventoryToGL@11(VAR ValueEntry@1000 : Record 5802);    BEGIN      WITH ValueEntry DO BEGIN        IF CalledFromAdjustment AND NOT PostToGL THEN          EXIT;        InvtPost.SetRunOnlyCheck(TRUE,NOT PostToGL,FALSE);        IF InvtPost.BufferInvtPosting(ValueEntry) THEN          InvtPost.PostInvtPostBufPerEntry(ValueEntry);        IF "Expected Cost" THEN BEGIN          SetValueEntry(ValueEntry,"Cost Amount (Expected)","Cost Amount (Expected) (ACY)",FALSE);          InvtPost.SetRunOnlyCheck(TRUE,TRUE,FALSE);          IF InvtPost.BufferInvtPosting(ValueEntry) THEN            InvtPost.PostInvtPostBufPerEntry(ValueEntry);          SetValueEntry(ValueEntry,0,0,TRUE);        END;      END;    END;***************** AFTER **************************************************************************    LOCAL PROCEDURE PostInventoryToGL@11(VAR ValueEntry@1000 : Record 5802);    BEGIN      WITH ValueEntry DO BEGIN        IF CalledFromAdjustment AND NOT PostToGL THEN          EXIT;        // MRH0005 >>        CLEAR(InvtPost);        // MRH0005 <<        InvtPost.SetRunOnlyCheck(TRUE,NOT PostToGL,FALSE);        IF InvtPost.BufferInvtPosting(ValueEntry) THEN          InvtPost.PostInvtPostBufPerEntry(ValueEntry);        IF "Expected Cost" THEN BEGIN          SetValueEntry(ValueEntry,"Cost Amount (Expected)","Cost Amount (Expected) (ACY)",FALSE);          // MRH0005 >>          CLEAR(InvtPost);          // MRH0005 <<          InvtPost.SetRunOnlyCheck(TRUE,TRUE,FALSE);          IF InvtPost.BufferInvtPosting(ValueEntry) THEN            InvtPost.PostInvtPostBufPerEntry(ValueEntry);          SetValueEntry(ValueEntry,0,0,TRUE);        END;      END;    END;**************************************************************************************************

Explanation

Posting a line for a serialized item where Quantity=1 works; however, when the quantity was increased, the error appeared. The debugger would stop in Codeunit 12, Gen. Jnl.-Post Line:

    GLEntry."Add.-Currency Debit Amount" := 0;   GLEntry."Add.-Currency Credit Amount" := -GLEntry."Additional-Currency Amount"; END;  GLEntryTmp := GLEntry; GLEntryTmp.INSERT;  NextEntryNo := NextEntryNo + 1;  IF CalcAddCurrResiduals THEN   HandleAddCurrResidualGLEntry;

As it turns out, when the posting routine was creating G/L Entry records, the NextEntryNo in Codeunit 12 was not being incremented properly. Clearing the C/AL global variable InvtPost (which points to Codeunit 5802, Inventory Posting To G/L) in Codeunit 22 causes the variable for Codeunit 12 to be cleared in Codeunit 5802, and NextEntryNo would be initialized properly (pointing to the next G/L Entry No. in the table … this happens in the local C/AL function InitCodeUnit in Codeunit 12).

Conclusion

Although this fixed the problem, be aware that this code is provided without warranty – the reader is advised to verify that this works for his or her installation of Dynamics NAV before implementing this code.

I am interested to see if anyone else has experienced this problem and how they have been able to overcome it.


Viewing all articles
Browse latest Browse all 64865

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>