Hi Kamil,
welcome

let's have a look at SetupNewLine():
SetUpNewLine(LastGenJnlLine : Record "Gen. Journal Line";Balance : Decimal;BottomLine : Boolean)
GenJnlTemplate.GET("Journal Template Name");
GenJnlBatch.GET("Journal Template Name","Journal Batch Name");
GenJnlLine.SETRANGE("Journal Template Name","Journal Template Name");
GenJnlLine.SETRANGE("Journal Batch Name","Journal Batch Name");
IF GenJnlLine.FIND('-') THEN BEGIN
"Posting Date" := LastGenJnlLine."Posting Date";
"Document Date" := LastGenJnlLine."Posting Date";
"Document No." := LastGenJnlLine."Document No.";
IF BottomLine AND
(Balance - LastGenJnlLine."Balance (LCY)" = 0) AND
NOT LastGenJnlLine.EmptyLine
THEN
"Document No." := INCSTR("Document No.");
END ELSE BEGIN
"Posting Date" := WORKDATE;
"Document Date" := WORKDATE;
IF GenJnlBatch."No. Series" <> '' THEN BEGIN
CLEAR(NoSeriesMgt);
"Document No." := NoSeriesMgt.TryGetNextNo(GenJnlBatch."No. Series","Posting Date");
END;
END;
IF GenJnlTemplate.Recurring THEN
"Recurring Method" := LastGenJnlLine."Recurring Method";
"Account Type" := LastGenJnlLine."Account Type";
"Document Type" := LastGenJnlLine."Document Type";
"Source Code" := GenJnlTemplate."Source Code";
"Reason Code" := GenJnlBatch."Reason Code";
"Posting No. Series" := GenJnlBatch."Posting No. Series";
"Bal. Account Type" := GenJnlBatch."Bal. Account Type";
IF ("Account Type" IN ["Account Type"::Customer,"Account Type"::Vendor,"Account Type"::"Fixed Asset"]) AND
("Bal. Account Type" IN ["Bal. Account Type"::Customer,"Bal. Account Type"::Vendor,"Bal. Account Type"::"Fixed Asset"])
THEN
"Account Type" := "Account Type"::"G/L Account";
VALIDATE("Bal. Account No.",GenJnlBatch."Bal. Account No.");
Description := '';
The function is part of Table 81, meaning all calls without a prefix (like LastGenJnlLine."Balance (LCY)") will refer to the actual record. You call it with itself as parameter, which has some effects:
- If the batch is not empty (at least one insert has already happened), the LastGenJnlLine will be the source of posting date, document date and document no. If the batch is empty, the function will try to use the NoSeries to get the next document no.
- If LastGenJnlLine has a balance (LCY) of 0 and it's on the bottom of the list, the function will try to increase the document no. You avoided this by setting the parameter to false.
Now, if you try someting like this:
{OnAfterImportRecord}
JournalLine.Init;
{do stuff}
JournalLine.SetUpNewLine(JournalLine, 0, FALSE);
{do stuff}
JournalLine.insert;
you would get a document no. on the first line only. The reason is the init() of JournalLine. It clears all fileds of the record, except for the primary key fields, and therefore the source of your document no. for the next line.
with best regards
Jens