Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

How to post Item journal manually through code

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 

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: How to post Item journal manually through code

    Thankyou now it's working for me.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,135 Super User 2024 Season 2 on at
    RE: How to post Item journal manually through code

    Please validate Item No.

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

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: How to post Item journal manually through code

    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
    Dividutt 200 on at
    RE: How to post Item journal manually through code

    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
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to post Item journal manually through code

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

  • Dividutt Profile Picture
    Dividutt 200 on at
    RE: How to post Item journal manually through code

    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
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: How to post Item journal manually through code

    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

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans