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
The error is easy to found -> Tip. Debug your source with 2 journal lines ;-)
Past that - sorry, but you've lost me. I've been staring at it too long I guess.
Set it behind the code GenJrnlLine.VALIDATE("Journal Batch Name",JrnlBatchName);
Also you doesn't need the evaluate.
So, your code must look like:
Regards
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."
That worked - thank-you very much.
I'm still a bit mystified why though.
Do you mean to look at the validate code in the "Account No" field of the table?
Again, many thanks.
Bob
yes, i mean the "Account No." - OnValidate() trigger in the table