# Next In Sequence

**URL:** <https://www.dynamicsuser.net/t/next-in-sequence/8163>\
**Category:** Developers Forum\
**Created:** [January 13, 2004, 7:21pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163 "2004-01-13T19:21:05Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![larryi](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@larryi](https://www.dynamicsuser.net/u/larryi)\
**Post date:** [January 13, 2004, 7:21pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/1 "2004-01-13T19:21:05Z")

</div>

I’m writing a routine to create G/L records. Am trying to get the last current Entry No. in the table, so that I can add one higher than this for the new record. In SQL, would use MAX to get highest number, then add one. What is equivalent in Navision? Also, do I need to lock the table when performing a function such as this?

---

<div class="post-metadata">

**Author:** ![lars\_westman](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@lars\_westman](https://www.dynamicsuser.net/u/lars_westman)\
**Post date:** [January 13, 2004, 7:34pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/2 "2004-01-13T19:34:14Z")

</div>

IF GLEntry.FIND(’+’) THEN NextNo := GLEnry.“Entry No.” + 1 ELSE NextNo := 1; But the normal way is to fill up a Gen Jnl Line and call the posting routine to post that line. That’s the way You should do it. In Navision we hardly ever write directly to ledger entries. Instead there are existing routines for posting journal lines which automatically does all the necessery controls (posting dates, dimensions and so on) for You.

---

<div class="post-metadata">

**Author:** ![larryi](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@larryi](https://www.dynamicsuser.net/u/larryi)\
**Post date:** [January 13, 2004, 7:52pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/3 "2004-01-13T19:52:00Z")

</div>

Lars: Thanks, great reply, worked perfectly. True, normally would post into table from Journal. This is a specialized case where we are creating ‘dummy’ summary stat records solely for purposes of feeding them over to secondary reporting package. So, posting from journal is not a req’t (or so I’ve been told! [:D])

---

<div class="post-metadata">

**Author:** ![FormerMember](https://avatars.discourse-cdn.com/v4/letter/f/74df32/32.png) [@FormerMember](https://www.dynamicsuser.net/u/FormerMember)\
**Post date:** [January 13, 2004, 7:54pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/4 "2004-01-13T19:54:23Z")

</div>

I whole heartedly agree with what Lars said. You should always import into Journals and never to Ledgers.

---

<div class="post-metadata">

**Author:** ![David\_Singleton](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/david_singleton/32/7471_2.png) [@David\_Singleton](https://www.dynamicsuser.net/u/David_Singleton)\
**Post date:** [January 13, 2004, 8:23pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/5 "2004-01-13T20:23:01Z")

</div>

> quote:
> 
> * * *
> 
> _Originally posted by larryi_ …(or so I’ve been told! [:D])
> 
> * * *

Larry, find them and shoot them. Even just for stats, you should never manually insert records directly into Navision. You may have corupted your database, and not even know it. Then someone comes to you at the begining of next year, and says “why can’t I close out the year? I keep getting a message about the gl entries no being concistant?” That or you get an error with rounding on a flow field that is near impossible to locate. Create the journal, and post it that way, you will save time, and have less clint issues later. Even if you have already done it, then for your clients sake, delete the entries and do it correctly.

---

<div class="post-metadata">

**Author:** ![CMDunbar](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@CMDunbar](https://www.dynamicsuser.net/u/CMDunbar)\
**Post date:** [January 14, 2004, 11:28am UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/6 "2004-01-14T11:28:10Z")

</div>

Larry, Take note of what these guys say. [;)] Many years ago, I tried the solution you are seeking, and sure enough I encountered all sorts of post development problems. Nightmare or what! [V] The sensible solution as these guys say, is using the journal as a transport and posting through the standard codeunits. You will save yourself a load of hassle! [:D] [;)]

---

<div class="post-metadata">

**Author:** ![CMDunbar](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@CMDunbar](https://www.dynamicsuser.net/u/CMDunbar)\
**Post date:** [January 14, 2004, 11:29am UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/7 "2004-01-14T11:29:42Z")

</div>

Larry, Take note of what these guys say. [;)] Many years ago, I tried the solution you are seeking, and sure enough I encountered all sorts of post development problems. Nightmare or what! [V] The sensible solution as these guys say, is using the journal as a transport and posting through the standard codeunits. You will save yourself a load of hassle! [:D] [;)]

---

<div class="post-metadata">

**Author:** ![CMDunbar](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@CMDunbar](https://www.dynamicsuser.net/u/CMDunbar)\
**Post date:** [January 14, 2004, 11:46am UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/8 "2004-01-14T11:46:01Z")

</div>

Larry, Take note of what these guys say. [;)] Many years ago, I tried the solution you are seeking, and sure enough I encountered all sorts of post development problems. Nightmare or what! [V] The sensible solution as these guys say, is using the journal as a transport and posting through the standard codeunits. You will save yourself a load of hassle! [:D] [;)]

---

<div class="post-metadata">

**Author:** ![David\_Singleton](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/david_singleton/32/7471_2.png) [@David\_Singleton](https://www.dynamicsuser.net/u/David_Singleton)\
**Post date:** [January 14, 2004, 5:44pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/9 "2004-01-14T17:44:06Z")

</div>

hi hi hi connull connull connull mouse mouse mouse problems problems problems ? ? ?

---

<div class="post-metadata">

**Author:** ![larryi](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@larryi](https://www.dynamicsuser.net/u/larryi)\
**Post date:** [January 14, 2004, 6:43pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/10 "2004-01-14T18:43:31Z")

</div>

OK, message heard loud and clear! I will write to Journal, then post from there. This is all quite new to me, so one more question: If I create Journal records for this specialized function, do I need to create new, separate routines that will post these records into G/L, or can the current posting routines accomodate? Thanks all for the helpful, spirited responses; very much appreciated.

---

<div class="post-metadata">

**Author:** ![Nelson](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@Nelson](https://www.dynamicsuser.net/u/Nelson)\
**Post date:** [January 14, 2004, 6:48pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/11 "2004-01-14T18:48:31Z")

</div>

The whole point made by Lars, David and Connull is that, once you import the records into a journal, you don’t have to worry about anything else. You just call the posting routine and let it take it from there. Remember: you can either do it automatically or just leave the records in the journal for a user to check before posting.

---

<div class="post-metadata">

**Author:** ![lars\_westman](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@lars\_westman](https://www.dynamicsuser.net/u/lars_westman)\
**Post date:** [January 14, 2004, 6:53pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/12 "2004-01-14T18:53:06Z")

</div>

Hi. Here’s some code from cu80 which might give som hints: As You can see You assign some values to a variable (a Gnl.Jnl. Line) and call the posting routine. Simple isn’t it! And You have all validations for free. ` GenJnlLine.INIT; GenJnlLine."Posting Date" := "Posting Date"; GenJnlLine."Document Date" := "Document Date"; GenJnlLine.Description := "Posting Description"; GenJnlLine."Shortcut Dimension 1 Code" := "Shortcut Dimension 1 Code"; GenJnlLine."Shortcut Dimension 2 Code" := "Shortcut Dimension 2 Code"; GenJnlLine."Reason Code" := "Reason Code"; GenJnlLine."Account Type" := GenJnlLine."Account Type"::Customer; GenJnlLine."Account No." := "Bill-to Customer No."; IF "Document Type" = "Document Type"::"Credit Memo" THEN GenJnlLine."Document Type" := 0 // Blank ELSE GenJnlLine."Document Type" := GenJnlLine."Document Type"::Payment; GenJnlLine."Document No." := GenJnlLineDocNo; GenJnlLine."External Document No." := GenJnlLineExtDocNo; IF "Bal. Account Type" = "Bal. Account Type"::"Bank Account" THEN GenJnlLine."Bal. Account Type" := GenJnlLine."Bal. Account Type"::"Bank Account"; GenJnlLine."Bal. Account No." := "Bal. Account No."; GenJnlLine."Currency Code" := "Currency Code"; GenJnlLine.Amount := TotalSalesLine."Amount Including VAT" + CustLedgEntry."Pmt. Disc. Possible"; GenJnlLine."Source Currency Code" := "Currency Code"; GenJnlLine."Source Currency Amount" := GenJnlLine.Amount; GenJnlLine.Correction := Correction; CustLedgEntry.CALCFIELDS(Amount); IF CustLedgEntry.Amount = 0 THEN GenJnlLine."Amount (LCY)" := TotalSalesLineLCY."Amount Including VAT" ELSE GenJnlLine."Amount (LCY)" := TotalSalesLineLCY."Amount Including VAT" + ROUND( CustLedgEntry."Pmt. Disc. Possible" * CustLedgEntry."Adjusted Currency Factor"); IF SalesHeader."Currency Code" = '' THEN GenJnlLine."Currency Factor" := 1 ELSE GenJnlLine."Currency Factor" := SalesHeader."Currency Factor"; GenJnlLine."Applies-to Doc. Type" := GenJnlLineDocType; GenJnlLine."Applies-to Doc. No." := GenJnlLineDocNo; GenJnlLine."Source Type" := GenJnlLine."Source Type"::Customer; GenJnlLine."Source No." := "Bill-to Customer No."; GenJnlLine."Source Code" := SrcCode; GenJnlLine."Posting No. Series" := "Posting No. Series"; GenJnlPostLine.RunWithCheck(GenJnlLine,TempJnlLineDim);` [code] … [/code] added

---

<div class="post-metadata">

**Author:** ![Nelson](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@Nelson](https://www.dynamicsuser.net/u/Nelson)\
**Post date:** [January 14, 2004, 7:06pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/13 "2004-01-14T19:06:08Z")

</div>

There is one thing I don’t quite grasp, when you say:

> quote:
> 
> * * *
> 
> _Originally posted by Larry_ This is a specialized case where we are creating ‘dummy’ summary stat records solely for purposes of feeding them over to secondary reporting package.
> 
> * * *

What does it mean? Are you exporting the data from Navision into a different program and you need these entries only because of this secondary program? When you post these G/L Entries, will it not make your Accounts reflect an unrealistic situation? Is it not better to simply add these summary entries during the export phase and not create them inside Navision?

---

<div class="post-metadata">

**Author:** ![apertierra](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@apertierra](https://www.dynamicsuser.net/u/apertierra)\
**Post date:** [January 14, 2004, 7:47pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/14 "2004-01-14T19:47:29Z")

</div>

To avoid affecting the Accounts use as balance account the same one you’re posting to… so it will clean itself. 🙂

---

<div class="post-metadata">

**Author:** ![CMDunbar](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@CMDunbar](https://www.dynamicsuser.net/u/CMDunbar)\
**Post date:** [January 15, 2004, 11:11am UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/15 "2004-01-15T11:11:30Z")

</div>

Hi David. It wasn’t me - must be this dodgy web site [:D]

---

<div class="post-metadata">

**Author:** ![larryi](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@larryi](https://www.dynamicsuser.net/u/larryi)\
**Post date:** [February 2, 2004, 7:01pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/16 "2004-02-02T19:01:08Z")

</div>

Thanks to everyone’s help and input, I have this routine working properly (yes!). Have one final issue to deal with - slowness. I built up the functionality incrementally, adding features bit by bit. At one point, I had program create Gen. Journal Lines, and then manually posting these lines in. This worked fine. But when I have RunWithCheck post programatically, it’s dog slow. Instead of a 5 minute runtime, it’s over 1/2 hour. Any way to change the way I call the posting routine to make it more efficient, or something else I can change?

---

<div class="post-metadata">

**Author:** ![David\_Singleton](https://sea1.discourse-cdn.com/flex023/user_avatar/www.dynamicsuser.net/david_singleton/32/7471_2.png) [@David\_Singleton](https://www.dynamicsuser.net/u/David_Singleton)\
**Post date:** [February 2, 2004, 8:55pm UTC](https://www.dynamicsuser.net/t/next-in-sequence/8163/17 "2004-02-02T20:55:19Z")

</div>

this is because of dimensions. at 1/2 hour for a one off routine, just leave it. If you monitor the database reads during a g/l journal post, you will see that the number or reads is proportional to the square of the number of lines that have dimensions. I am pretty sure I discussed this in an earlier thread, so try searching. You can speed it up by posting many smaller journals. I had thought it was fixed in 3.60 though.
