Hi all
I am trying to adjust all items to 0 via the revaluation journal, but it does not seem to work proberly. I end up with several item ledger entries with actual cost <> 0. If I run the code again afterwards new revaluation lines are created. Also I would like to know if there is another way to do this or if I am doing it the right way.
My code looks like this.
OnRun()
ItemJournalLine2.SETRANGE("Journal Template Name",'VÆRDIJUST');
ItemJournalLine2.SETRANGE("Journal Batch Name",'STANDARD');
ItemJournalLine2.DELETEALL;
Item.FIND('-');
REPEAT
ItemLedgerEntry.SETRANGE("Item No.",Item."No.");
ItemLedgerEntry.SETRANGE(Positive,TRUE);
ItemLedgerEntry.SETRANGE("Completely Invoiced",TRUE);
IF(ItemLedgerEntry.FIND('-')) THEN BEGIN
REPEAT
ItemLedgerEntry.CALCFIELDS("Cost Amount (Actual)");
IF(ItemLedgerEntry."Cost Amount (Actual)" <> 0) THEN
InsertRevaluationLine(ItemLedgerEntry);
UNTIL ItemLedgerEntry.NEXT = 0;
END;
UNTIL Item.NEXT = 0;
LOCAL InsertRevaluationLine(ItemLedgerEntryRec : Record "Item Ledger Entry")
LineNo += 10000;
CurrentJnlBatchName := 'STANDARD';
ItemJournalLine.INIT;
ItemJournalLine.VALIDATE("Value Entry Type",ItemJournalLine."Value Entry Type"::Revaluation);
ItemJournalLine.VALIDATE("Source Code",'VÆRDIRGKLD');
ItemJournalLine."Journal Template Name" := 'VÆRDIJUST';
ItemJournalLine."Journal Batch Name" := 'STANDARD';
ItemJournalLine."Line No." := LineNo;
ItemJournalLine.VALIDATE("Document No.",'T04001');
ItemJournalLine.VALIDATE("Item No.",ItemLedgerEntryRec."Item No.");
ItemJournalLine.VALIDATE("Applies-to Entry",ItemLedgerEntryRec."Entry No.");
ItemJournalLine.VALIDATE("Unit Cost (Revalued)",0);
ItemJournalLine.INSERT(TRUE);
Thanks in advance!
*This post is locked for comments