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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Post Item journal lines automatically with codeunit?

(0) ShareShare
ReportReport
Posted on by 51

Hi,

I am using power automate to create item journal lines from other data source, I can to create an API and use it in the flow to create the lines in the journal, and it works:

8741.p1.png

the next step is to post the line in the item ledger entries, is known for me that I need to use a codeunit and deploy as web service for this (documentation HERE).

But I'm not get very well the steps to create the codeunit, I don't know how to start, maybe someone have a usefull example or a better documentation?

Any help is appreciated, I've been stuck with this for several days.

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    133 on at

    For a different scenario I created a codeunit to post a recurring journal. This blog explains how: joshanglesea.wordpress.com/.../

    Adapt it to your scenario.

  • srueda Profile Picture
    51 on at

    Thank you, I have created the codeunit and now I can post the Item Journal Line.

    But, the item journal line is still in the journal, how can I delete it? That's a problem for me because I need to run the flow a lot of times.

    2046.q2.png

    The code of my codeunit is the following:

    codeunit 50100 "PostAction"
    {
        procedure postJrnl()
        var
            ItemJrnl: Record "Item Journal Line";
        begin
            ItemJrnl.SetFilter("Journal Template Name", 'ITEM');
            ItemJrnl.SetRange("Journal Batch Name", 'DEFAULT');
            if ItemJrnl.FindSet() then begin
                Codeunit.Run(Codeunit::"Item Jnl.-Post Line", ItemJrnl)
            end;
        end;
    }

    Have I to modified something in the code?

    Sorry if there are some problem with the code, Im not developer.

    Thank you!

  • Suggested answer
    Bilal Haider Profile Picture
    414 on at

    Hi,

    Using this code you will not be able to post multiple lines. It will work only for 1 line.

    Replace the line codeunit.Run(Codeunit::"Item Jnl.-Post Line", ItemJrnl) with codeunit.Run(Codeunit::"Item Jnl.-Post Batch",ItemJrnl)

    Using this codeunit multiple lines can be posted and lines will be deleted automatically as they are posted.

  • srueda Profile Picture
    51 on at

    Yes!! Thank you a lot of!! :DD

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

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 3,151

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,443 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,092 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans