Thursday, September 16, 2021

Business Central - Adjust Cost - Item Ledger entry is Missing

 If a database has become corrupted, or item ledger entries have been lost, the Adjust cost job will give an error when it encounters value entries that point to non-existent item ledger entries.

First resolution - restore your last backup. Working with a damaged database is never fun. I do not 

recommend you ever do anything in the rest of this post.

-------------------------------------------------------

--------------------------------

Run this to identify VE's with missing ILE's.

You can either insert the missing ILE's, or delete the VE's with the bad references.


SELECT VE.timestamp, VE.[Entry No_], VE.[Item No_], VE.[Posting Date], VE.[Item Ledger Entry Type], VE.[Source No_], VE.[Document No_], VE.Description, VE.[Location Code], VE.[Inventory Posting Group], VE.[Source Posting Group], 

                  VE.[Item Ledger Entry No_], VE.[Valued Quantity], VE.[Item Ledger Entry Quantity], VE.[Invoiced Quantity], VE.[Cost per Unit], VE.[Sales Amount (Actual)], VE.[Salespers__Purch_ Code], VE.[Discount Amount], VE.[User ID], VE.[Source Code], 

                  VE.[Applies-to Entry], VE.[Global Dimension 1 Code], VE.[Global Dimension 2 Code], VE.[Source Type], VE.[Cost Amount (Actual)], VE.[Cost Posted to G_L], VE.[Reason Code], VE.[Drop Shipment], VE.[Journal Batch Name], 

                  VE.[Gen_ Bus_ Posting Group], VE.[Gen_ Prod_ Posting Group], VE.[Document Date], VE.[External Document No_], VE.[Cost Amount (Actual) (ACY)], VE.[Cost Posted to G_L (ACY)], VE.[Cost per Unit (ACY)], VE.[Document Type], 

                  VE.[Document Line No_], VE.[Order Type], VE.[Order No_], VE.[Order Line No_], VE.[Expected Cost], VE.[Item Charge No_], VE.[Valued By Average Cost], VE.[Partial Revaluation], VE.Inventoriable, VE.[Valuation Date], VE.[Entry Type], 

                  VE.[Variance Type], VE.[Purchase Amount (Actual)], VE.[Purchase Amount (Expected)], VE.[Sales Amount (Expected)], VE.[Cost Amount (Expected)], VE.[Cost Amount (Non-Invtbl_)], VE.[Cost Amount (Expected) (ACY)], 

                  VE.[Cost Amount (Non-Invtbl_)(ACY)], VE.[Expected Cost Posted to G_L], VE.[Exp_ Cost Posted to G_L (ACY)], VE.[Dimension Set ID], VE.[Job No_], VE.[Job Task No_], VE.[Job Ledger Entry No_], VE.[Variant Code], VE.Adjustment, 

                  VE.[Average Cost Exception], VE.[Capacity Ledger Entry No_], VE.Type, VE.No_, VE.[Return Reason Code],

                  ILE.[Entry No_] AS ILENo

FROM     [CRONUS$Item Ledger Entry] AS ILE RIGHT OUTER JOIN

                  [CRONUS$Value Entry] AS VE ON ILE.[Entry Type] = VE.[Item Ledger Entry Type] AND ILE.[Entry No_] = VE.[Item Ledger Entry No_]

WHERE  (ILE.[Entry No_] IS NULL and VE.[Posting Date]>= '2021-08-10')