web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

How to post Item journal manually through code

(0) ShareShare
ReportReport
Posted on by 200

Hi I want to post Item journal line through Al code,

For posting date, entry type, item number and quantity.

So after posting I want to get that line in item ledger entries, how can we do it through Al code please help.

Thankyou 

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,788 Moderator on at

    Hi,

    You can try below code

    // Define variables for journal template name and batch name
    JournalTemplateName := 'Inventory';
    BatchName := 'Batch1';
    
    // Create a new Item Journal batch
    ItemJournalBatch.SETRANGE("Journal Template Name", JournalTemplateName);
    ItemJournalBatch.SETRANGE("Batch Name", BatchName);
    ItemJournalBatch.INSERT;
    
    // Create a new journal line
    JournalLine.SETRANGE("Journal Template Name", JournalTemplateName);
    JournalLine.SETRANGE("Journal Batch Name", BatchName);
    JournalLine.INSERT;
    
    // Populate the journal line fields
    JournalLine."Gen. Bus. Posting Group" := Item."Gen. Bus. Posting Group";
    JournalLine."Posting Date" := WORKDATE;
    JournalLine."Item Ledger Entry Type" := ItemLedgerEntryType::Positive;
    JournalLine."Document Type" := DocumentType::Item;
    JournalLine."Item No." := 'ITEM001';
    JournalLine."Location Code" := 'WH01';
    JournalLine.Quantity := 10;
    
    // Post the Item Journal batch
    ItemJournalBatch.VALIDATE("No. of Journal Lines");
    ItemJournalBatch.RUN;
    

  • Dividutt Profile Picture
    200 on at

    pageextension 50102 "ItemJournal line" extends "Item List"

    {

       actions

       {

           addfirst(processing)

           {

               action(Test)

               {

                   Caption = 'Post something';

                   ApplicationArea = all;

                   trigger OnAction()

                   var

                       GLPost: Codeunit "Item Jnl.-Post Line";

                       Line: Record "Item Journal Line";

                   begin

                       Line.Init();

                       Line."Posting Date" := TODAY();

                       Line."Entry Type" := Line."Entry Type"::"Negative Adjmt.";

                       Line."Document No." := 'A2134';

                       Line."Item No." := '1906-S';

                       Line.Description := 'Item Quantity';

                       Line.Quantity := 3;

                       Line.Amount := 70;

                       GLPost.RunWithCheck(Line);

                   end;

               }

           }

       }

    }

    as I has something like this anything to update?

  • Suggested answer
    Nitin Verma Profile Picture
    21,788 Moderator on at

    You need to define, Template name, Batch name and Line no. field as well.

  • Dividutt Profile Picture
    200 on at

    As you mentioned Itemjournalbatch and journal line what to assign them like is it Recorde or codeunit?

    And where to define line no

    Can you update in my code?

    Thankyou

  • Dividutt Profile Picture
    200 on at

    When I am posting now I am getting this issue:

    Gen. Prod. Posting Group must have a value in Item Journal Line: Journal Template Name=, Journal Batch Name=, Line No.=0. It cannot be zero or empty.

  • Verified answer
    Mohana Yadav Profile Picture
    61,184 Super User 2026 Season 1 on at

    Please validate Item No.

    Line.Validate("Item No.",'1906-S');

  • Dividutt Profile Picture
    200 on at

    Thankyou now it's working for me.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,986 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,071 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 975 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans