Inserting lines into the journal line table

SoloperSoloper Member Posts: 102
Hi all again;

I searched the forum but couldnt find the solution.

I am trying to insert sum records which are collected from G/L Entry table into the journal line. But it adds only one record and if there is another one it gives the following error :

----
The Gen. Journal Line already exists.

Identification fields and values :

Journal Template Name='TEMP1', Journal Batch Name="TEMPBATCH", Line No.='0'
----
I think the porblem is with the line no. It increase by one for every single record but it keeps 0 for line no and crush.

The code is below :

SourceTable for the form is G/L Entry
IF Rec.FINDFIRST THEN;

REPEAT

JournalLine.INIT;

JournalLine."Journal Template Name":='TEMP1';
JournalLine.VALIDATE("Journal Template Name");

JournalLine."Journal Batch Name" := 'TEMPBATCH';
JournalLine.VALIDATE("Journal Batch Name");

JournalLine."Account Type":= 0;
JournalLine.VALIDATE("Account Type");

JournalLine."Account No.":="G/L Account No.";
JournalLine.VALIDATE("Account No.");

JournalLine."Posting Date":= "Posting Date";
JournalLine.VALIDATE("Posting Date");

JournalLine."Credit Amount":=Amount;
JournalLine.VALIDATE("Credit Amount");

JournalLine."Bal. Account Type" := 3;
JournalLine.VALIDATE("Bal. Account Type");

JournalLine."Bal. Account No." := BankAccount."No.";
JournalLine.VALIDATE("Bal. Account No.");

JournalLine.INSERT;

UNTIL Rec.NEXT = 0;

Answers

  • vijay_gvijay_g Member Posts: 884
    IF Rec.FINDFIRST THEN;

    REPEAT

    JournalLine.INIT;

    JournalLine."Journal Template Name":='TEMP1';
    JournalLine.VALIDATE("Journal Template Name");

    JournalLine."Journal Batch Name" := 'TEMPBATCH';
    JournalLine.VALIDATE("Journal Batch Name");


    JournalLine.INSERT;

    UNTIL Rec.NEXT = 0;
    [/quote]



    you have to insert line no for each record like..
    GenJnlLine."Line No." := GenJnlLine."Line No." + 10000;
    because line no is also part of PK..


    Vijay Gupta
  • SoloperSoloper Member Posts: 102
    Works..

    Thanks Vijay.
  • kinekine Member Posts: 12,562
    never use FINDFIRST with REPEAT UNTIL. [-X

    This is a MUST KNOW for all developers...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.