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

Allow post and send only when there's inventory.

(0) ShareShare
ReportReport
Posted on by 50

Hi there, 

I'm struggling with something. I have a sales order and when I choose to 'post and send', I select 'ship and invoice' after I finish all the steps I get the error message 'Insufficient inventory'. But still a posted sales invoice is created with 0 value lines. How can I stop the post and send if there's no items inventory. I'm pretty new in AL language I have a project and already have an extension on the sales order page.

Any help will be appreciated.

Thanks in advance.

  • Suggested answer
    YUN ZHU Profile Picture
    104,190 Super User 2026 Season 2 on at

    Hi, This appears to be a customization issue.

    You can step through the debugger to see when the sales invoice was created but not rolled back when the error was reported.

    This may be related to Commit method or temporary tables.

    Hope this can give you some hints.

    Thanks.

    ZHU

  • Suggested answer
    Mohana Yadav Profile Picture
    61,260 Super User 2026 Season 2 on at

    You can set "Prevent Negative Inventory" on the item to Yes.

    pastedimage1674793348833v1.png

  • yaza Profile Picture
    50 on at

    Hi I think you are right we have some customisations. I have an after insert trigger on "Sales Invoice Header" and there I do a commit. But the error comes after this action and the SalesInvoice is already committed. But when I remove the commit from this after insert in the correct situation (with no error), the app freezes and nothing happens. Have you got any idea why this is?

  • Suggested answer
    IB-29041624-0 Profile Picture
    1,191 Moderator on at

    Maybe you should try to share the code that you have written?

  • Verified answer
    YUN ZHU Profile Picture
    104,190 Super User 2026 Season 2 on at

    I think it is the "Commit" problem, I suggest to remove this Commit.
    If it freezes, there may be an infinite loop in processing , and you should investigate that.

    Although it is more troublesome, if you debug step by step, you should be able to find the cause of the problem.

    Hope this helps.

    Thanks.

    ZHU

  • yaza Profile Picture
    50 on at

    The commit was the problem indeed here's my code:

    Table extension: SalesInvoiceShipping extends "Sales Invoice Header"

    tableextension 50400 SalesInvoiceShipping extends "Sales Invoice Header"
    {
    trigger OnAfterInsert()
        var
            UpdateRef: codeunit "Update Ref";
            EnableText: Text;
            EnableBool: Boolean;
        begin      
                        UpdateRef.QueueExport(Rec."No.")     
        end;
    }

    Codeunit UpdateRef:

    codeunit 50418 "Update Ref"
    {
     procedure QueueExport(RecNo: Code[20])
        var
            SalesHeader: record "Sales Invoice Header";
            ExtWarehouseRef: record "Ext Warehouse Ref";
        begin
            if SalesHeader.Get(RecNo) then begin
                ExtWarehouseRef.Init();
                ExtWarehouseRef."No." := RecNo;
                ExtWarehouseRef."Order Status" := 'Queued';
                ExtWarehouseRef."Order Export Time" := CurrentDateTime();
                ExtWarehouseRef.Insert(true);
                //Commit(); this was the problem
            end;
        end;
    }
    After I removed the commit, my problem was solved and the sales invoice was no longer created with 0 value lines.
    Thank you very much for all the help.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 545 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 354 Super User 2026 Season 2

#3
Grigorios Mavrogeorgis Profile Picture

Grigorios Mavrogeorgis 228 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans