mibuso.com

Microsoft Business Solutions online community
It is currently Tue May 21, 2013 5:40 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Gen. Journal Line "Document No."
PostPosted: Sun May 20, 2012 9:50 am 
Offline

Joined: Sun May 20, 2012 9:35 am
Posts: 2
Country: Poland (pl)
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()
Code: Select all
JournalLine.SetUpNewLine(JournalLine, 0, FALSE);


Top
 Profile E-mail  
 
 Post subject: Re: Gen. Journal Line "Document No."
PostPosted: Sun May 20, 2012 11:46 am 
Offline

Joined: Sat May 12, 2007 9:19 am
Posts: 271
Location: Falkensee
Country: Germany (de)
Hi Kamil,

welcome :) let's have a look at SetupNewLine():
Code: Select all
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:

Code: Select all
{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


Top
 Profile E-mail  
 
 Post subject: Re: Gen. Journal Line "Document No."
PostPosted: Sun May 20, 2012 12:17 pm 
Offline

Joined: Sun May 20, 2012 9:35 am
Posts: 2
Country: Poland (pl)
Jens You are GENIUS !!!!! Thank You !! :) \:D/


Top
 Profile E-mail  
 
 Post subject: Re: Gen. Journal Line "Document No."
PostPosted: Mon Dec 24, 2012 4:37 pm 
Offline

Joined: Mon Dec 24, 2012 4:26 pm
Posts: 1
Country: Poland (pl)
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:


Image

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

Do you know any solution for this?


Top
 Profile E-mail  
 
 Post subject: Re: Gen. Journal Line "Document No."
PostPosted: Thu Dec 27, 2012 9:59 pm 
Offline

Joined: Sat May 12, 2007 9:19 am
Posts: 271
Location: Falkensee
Country: Germany (de)
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


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot], vaprog, wakestar and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: