Ledger Entry Dimension Error when posting consumption

dndn Member Posts: 71
Hi
We don't want the PostConsumption routine to stop because of some Items with product code "Screw", is not in inventory.
(sounds crazy but we want this way).
So I have done some changes in cu 22.
Before the routine InsertConsumpEntry called. I'll posting an Item Journal with quanity that needs.
Problem is when I posting from consumption journal, I'll get Ledger Entry Dimension Error
"Table Id:32 ,Entry No. 835556, Dimensionkod:Parts " is already exists.

All tips is welcome..
...

IF recItem."Product Group Code" = 'SCREW' THEN
BEGIN
recItem.CALCFIELDS(Inventory);
IF recItem.Inventory < QtyToPost THEN
InsertScrewsEntry(QtyToPost-recItem.Inventory,ProdOrderComp);
END;

IF ProdOrderCompModified THEN
InsertConsumpEntry(ProdOrderComp,"Line No.",QtyToPost,FALSE)
ELSE
.....

Have I missed something in my routine below?

InsertScrewsEntry(Qty : Decimal;ProdComp : Record "Prod. Order Component")
Commit;
Setup.get;
CLEAR(recItemJnlLine);
recItemJnlLine.SETRANGE("Journal Template Name",Setup."Journal Template Name");
recItemJnlLine.SETRANGE("Journal Batch Name",Setup."Journal Batch Name");
IF recItemJnlLine.FIND('-') THEN
recItemJnlLine.DELETEALL;

recItemJnlLine.INIT;
recItemJnlLine."Journal Template Name" := Setup."Journal Template Name";
recItemJnlLine."Journal Batch Name" := Setup."Journal Batch Name";
recItemJnlLine.SetUpNewLine(recItemJnlLine);
recItemJnlLine."Line No." := 10000;
recItemJnlLine.INSERT(TRUE);

recItemJnlLine.VALIDATE("Posting Date", TODAY);
recItemJnlLine.VALIDATE("Entry Type",recItemJnlLine."Entry Type"::"Positive Adjmt.");
recItemJnlLine.VALIDATE("Item No.", ProdComp."Item No.");
recItemJnlLine.VALIDATE(Quantity,Qty);
recItemJnlLine."Location Code" := ProdComp."Location Code";
recItemJnlLine.MODIFY;
COMMIT;

cuPost.SkipDialog(TRUE);
cuPost.RUN(recItemJnlLine); //''Cu 241

Comments

  • ara3nara3n Member Posts: 9,256
    You should not use COMMITS in your code. Why are you using it?



    second why are you inserting the ItemJournal Line?

    recItemJnlLine.INSERT(TRUE);

    You should not use

    cuPost.RUN(recItemJnlLine);

    but instead use

    cuPost.RUNWITHCHECK(recItemJnlLine,TempDIMENSION);


    Also your code should not be called within posting of another Item journal

    I suggest to call your code before calling standard NAV Posting routine. You should it from OnPush trigger of the form.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • dndn Member Posts: 71
    ara3n wrote:
    You should not use COMMITS in your code. Why are you using it?

    Commit is for prepared system for new transaction..

    second why are you inserting the ItemJournal Line?

    recItemJnlLine.INSERT(TRUE);

    I want to put the needed quantity in inventory to cover the needed consumption and it's why I called CuPost below

    You should not use

    cuPost.RUN(recItemJnlLine);

    but instead use

    cuPost.RUNWITHCHECK(recItemJnlLine,TempDIMENSION);
    But there is no RUNWITHCHECK in codeunit 241 and what is TempDimension, how should I write the code??

    Also your code should not be called within posting of another Item journal

    I suggest to call your code before calling standard NAV Posting routine. You should it from OnPush trigger of the form.

    U meant in form 99000846?
Sign In or Register to comment.