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

Notifications

Announcements

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)
  • Dividutt Profile Picture
    200 on at

    Thankyou now it's working for me.

  • Verified answer
    Mohana Yadav Profile Picture
    61,019 Super User 2025 Season 2 on at

    Please validate Item No.

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

  • 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.

  • 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

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

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

  • 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,710 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;
    

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,513

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 742 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 706 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans