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
welcome let's have a look at SetupNewLine():
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:
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
my code is:
http://wklej.org/id/905298/
Do you know any solution for this?
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