Options

Gen. Journal Line "Document No."

KamilKamil Member Posts: 3
Hello Everybody !
This is my first post in this forum. I'm a beginner in using Microsoft Dynamics Nav and unfortunately I'm facing now problem. I created DataImport which load lines from external file to table. Then I parse every line in this table and look information I need to create Record in Gen. Journal Line. Of course I created a Journal Template Name and J. Batch Name. Now getting to the point. My problem is that, when I do INSERT() on Gen. Journal Line variable there is no value in "Document No.". I search Internet and I read that using SetUpNewLine() could solve my problem. So I used this function and all I have is value for only first Record in Gen. Journal Line. Does anyone may know what I'm doing wrong?
This is the way I use SetUpNewLine()
JournalLine.SetUpNewLine(JournalLine, 0, FALSE);

Comments

  • Options
    jglathejglathe Member Posts: 639
    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
  • Options
    KamilKamil Member Posts: 3
    Jens You are GENIUS !!!!! Thank You !! :) \:D/
  • Options
    dominik00dominik00 Member Posts: 1
    I have problem with execution of function setupnewline() in Gen. Journal Line. When i run this function in my custom CodeUnit, a get the following error:


    20zy894.jpg

    my code is:
    http://wklej.org/id/905298/

    Do you know any solution for this?
  • Options
    jglathejglathe Member Posts: 639
    Hi Dominik,

    your code does not contain the functions mentioned in the error message. I would guess, though:

    Do you call your codeunit with the "if codeunit.run()" clause? Then any write transaction opened before this call would lead to the same error.

    Since you mentioned getting the error with SetupNewLine() in your code, I would assume there is this code in one of the validate triggers called by SetupNewLine, in T81. Are there modifications on T81?

    Looking at your example code, the commit() doesn't look right. To test if there is a write transaction open, you could call it before SetupNewLine(). I would avoid this in production code, though.

    with best regards

    Jens
Sign In or Register to comment.