Problem setting journal line dimension

bhalpinbhalpin Member Posts: 309
Hi.

I've written code to populate a journal batch, but am having a weird problem.

I have a function EntryCreate that is called to create a journal line. I have two dimension values to set - dimensions 1 and 3.

Hunting around I see how dimensions > 2 are indirectly stored in table 356, "Journal Line Dimension", and see in the table "Gen. Journal Line" there is a function "ValidateShortcutDimCode". This is called by objects like Form 39 "General Journal" to set a dimension value in the line. ValidateShortcutDimCode dives off into DimensionManagement with the end result being an add/modify/delete in the "Journal Line Dimension" table.

Ok. no problemo. I added the call to ValidateShortcutDimCode to set my dimension 3 value and started testing.

Here's my problem: I find that if I call my function to create a journal line several times, only the *last* journal line gets dimension 3 populated properly. For example, if I call it six times, the 1st five journal lines have no corresponding record in "Journal Line Dimension", but the sixth is there. Other numbers of calls confirm that only the last seems to ever 'stick'.

Here is my code:
EntryCreate(
        GLAccount : Record "G/L Account";
        Description : Text[50];
        Amount : Decimal;
        Dim1Code : Code[20];
        Dim3Code : Code[20]
)
GenJrnlLine.INIT;
GenJrnlLine.VALIDATE("Jrnl Template Name",JrnlTemplateName);
GenJrnlLine.VALIDATE("Jrnl Batch Name",JrnlBatchName);
EVALUATE(GenJrnlLine."Account Type" ,'G/L Account');
GenJrnlLine.VALIDATE("Account No.",GLAccount."No.");
GenJrnlLine.VALIDATE("Line No.",LineNo);
GenJrnlLine.VALIDATE("Posting Date","End Date");
GenJrnlLine.VALIDATE(Description,Description);
GenJrnlLine.VALIDATE(Amount,Amount);
GenJrnlLine.VALIDATE("Shortcut Dimension 1 Code",Dim1Code);
GenJrnlLine.INSERT(TRUE);
LineNo += 10000;
GenJrnlLine.ValidateShortcutDimCode(3,Dim3Code);

Does anyone have any ideas as to why only the last call results in a proper dimension entry?

Thanks in advance!

Bob ](*,)

Comments

  • garakgarak Member Posts: 3,263
    is "LineNo" a global or a local variable? Why do you set it at the end to 10000++ ?
    The error is easy to found -> Tip. Debug your source with 2 journal lines ;-)
    Do you make it right, it works too!
  • bhalpinbhalpin Member Posts: 309
    LineNo is a global, initialized to 10000 before any calls to this code are made.

    Past that - sorry, but you've lost me. I've been staring at it too long I guess.
  • garakgarak Member Posts: 3,263
    OK, littlie tip. Move following line GenJrnlLine.validate"Line no.",LineNo); up.
    Set it behind the code GenJrnlLine.VALIDATE("Journal Batch Name",JrnlBatchName);

    Also you doesn't need the evaluate.

    So, your code must look like:
    LineNo := 1000;
    
    EntryCreate(
            GLAccount : Record "G/L Account";
            Description : Text[50];
            Amount : Decimal;
            Dim1Code : Code[20];
            Dim3Code : Code[20]
    )
    
    GenJrnlLine.INIT;
    GenJrnlLine."Jrnl Template Name" := JrnlTemplateName;
    GenJrnlLine."Jrnl Batch Name" := JrnlBatchName;
    GenJrnlLine."Line No." := LineNo;
    GenJrnlLine.validate("Account Type",GenJrnlLine."Account Type"::"G/L");
    GenJrnlLine.VALIDATE("Account No.",GLAccount."No.");
    GenJrnlLine.VALIDATE("Posting Date","End Date");
    GenJrnlLine.Description := Description;
    GenJrnlLine.VALIDATE(Amount,Amount);
    GenJrnlLine.VALIDATE("Shortcut Dimension 1 Code",Dim1Code);
    GenJrnlLine.ValidateShortcutDimCode(3,Dim3Code); 
    GenJrnlLine.INSERT(TRUE);
    LineNo += 10000;
    

    Regards
    Do you make it right, it works too!
  • garakgarak Member Posts: 3,263
    Other tip.
    If you fill a table via code, set first the pk fields and then the others.
    To know, why your source doesn't work, look behind the source in "Account No."
    Do you make it right, it works too!
  • bhalpinbhalpin Member Posts: 309
    Hi Garak.

    That worked - thank-you very much.

    I'm still a bit mystified why though.
    To know, why your source doesn't work, look behind the source in "Account No."

    Do you mean to look at the validate code in the "Account No" field of the table?

    Again, many thanks.

    Bob
  • garakgarak Member Posts: 3,263
    Please no problem, for this these forum exist ;-)

    yes, i mean the "Account No." - OnValidate() trigger in the table
    Do you make it right, it works too!
Sign In or Register to comment.