Auto Journal posting


Could someone let me know how to invoke Journal posting from a code unit.


Hi Sudhakar,

Which version of NAV you are using ?

Is it classic client or RTC version ?

I have to get it done for Nav 5.0… Classic client only.

Currently journal posting is invoked from a codeunit, so I’m a little puzzled exactly what it is that you’re trying to do?

You say autoposting? That’s not a problem, but if your employees are manually entering the journal, then how should this codeunit know when they are done?

Journal entries will not be done manually, They will be imported from a csv.


Do you want to post the journals which automatically imported from csv file ?


Marshal. J


I need to import journal lines from a 3rd party system to Nav 5.0.

I’m looking to use dataport to load journal entries from a csv to journal table.

Invoke the dataport from a codeunit and also need to post the imported journal lines.

Appreciate if I can get some references or samples to do this job.

You need to import the entries in the journal first through dataport & after call the codeunit to post the journals.

You will need separate template, batch & no. series.

Which code unit do I need to run for posting?

What do I need to do to suppress the error messages or warnings?


Hi Sudhakar,

May I suggest that you read my blog post on which tables to use here I describe the exact case you describe above.

You need to use codeunit 12 (Gen. Jnl.-Post Line) to post the lines after you have imported them. But I suggest that you do not physically insert them into the Gen. journal line table, but inserts them into a temporary copy of the table and then post them all in one step.

You should not suppress error messages, but make sure that you have tested everything when importing the data. Error handling is very important whenever you deal with an ERP system, as you otherwise might end up making the system inconsistent.


Which journal you are trying to import and post ? following example shows to import and post Item Journal the same way u can post the journal which you want

Create a code unit and create two variables as like below

Name DataType Subtype Length
ImportDp Dataport Sample DP
ItemJnl Record Item Journal Line

First variable is the dataport which will be used to Export/Import Data

Second is Record variable of the journal table


ImportDp.FILENAME:= ‘C:\Documents and Settings\marshelj\Desktop\1.csv’;

ItemJnl.SETRANGE(ItemJnl.“Journal Template Name”,‘ITEM’);
ItemJnl.SETRANGE(ItemJnl.“Journal Batch Name”,‘DEFAULT’);
CODEUNIT.RUN(CODEUNIT::“Item Jnl.-Post”,ItemJnl);
UNTIL ItemJnl.NEXT = 0;

Marshal. J

If I get the data to temporary tables, Can I post to Ledger directly without bringing data to Journal Line table? Or do I need to bring in the data to Journal line table?

Could you share any sample code that does the job?

Please do not use the code outlined above as it could create a lot of issues.

  1. Assumption Problem: It is assumed that the DP is using Journal Template ITEM and Name DEFAULT
    asssumptions are not a friend of a programmer

  2. You should not use FINDFIRST in this case, rather use FINDSET as it does not hurt the SQL Server in the same manner, when running on a CSide database it does not make a difference, but after updating to SQL it will slow down the System

  3. You should not use the CODEUNIT.RUN(ID) Syntax in this case as it would create a new Register for every single line you are posting. Rather declare the CU as a variable and run that like ItemJnlPost.RUN(IntemJnl).

Anyway I would rather run the post inside the dataport itself in the “OnPostDataItem” Trigger.

It is an absolute NoGo to write directly to ledger entry tables.

Please do it the Journal Line/ Call Post CU way only.

Otherwise you run into inconsistencies you will not be able to rectify properly.

The nice thing about NAV that it provides a single method to generate ledgers based on the same logic from everywhere.
Do it the NAV way and generate Journal lines which you hand over to the posting CU.