Skip to main content

Notifications

Announcements

No record found.

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

Post Item journal lines automatically with codeunit?

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.

  • srueda Profile Picture
    srueda 51 on at
    RE: Post Item journal lines automatically with codeunit?

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

  • Suggested answer
    Bilal Haider Profile Picture
    Bilal Haider 45 on at
    RE: Post Item journal lines automatically with codeunit?

    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
    srueda 51 on at
    RE: Post Item journal lines automatically with codeunit?

    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
    JAngle Profile Picture
    JAngle 33,159 on at
    RE: Post Item journal lines automatically with codeunit?

    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.

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans