Negate the value towards Item Ledger Entry

mysamzamysamza Member Posts: 49
edited 2020-01-05 in NAV Three Tier
I am trying to negate the value to negative based on a condition, and no matter what method I apply to negate it, I get positive value.

Here is the code;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Item Jnl.-Post Line", 'OnAfterInitItemLedgEntry', '', true, true)]
    procedure MyProcedure2(ItemJournalLine: Record "Item Journal Line"; var NewItemLedgEntry: Record "Item Ledger Entry")


        if NewItemLedgEntry.Positive = true then
            NewItemLedgEntry."Carat Wt" := ItemJournalLine."Carat Wt"
            if NewItemLedgEntry.Positive = false then
                NewItemLedgEntry."Carat Wt" := (ItemJournalLine."Carat Wt") * -1;

Carat Wt is a custom field I created. The value gets passed on fine, but without it being negative. In the second condition, I am multiplying by -1 yet the value gets saved as positive.


  • Jan_VeenendaalJan_Veenendaal Member Posts: 206
    1. If the value of ItemJournalLine."Carat Wt" in the second case already is negative, then your code will always result in a positive value in the NewItemLedgEntry record.

    2. The structure of your code is not really clear. I would propose something like:
      if NewItemLedgEntry.Positive then
        NewItemLedgEntry."Carat Wt" := ItemJournalLine."Carat Wt"
        NewItemLedgEntry."Carat Wt" := - ItemJournalLine."Carat Wt"

    Jan Veenendaal
Sign In or Register to comment.