web
You’re offline. This is a read only version of the page.
close
Skip to main content
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.

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    93,222 Super User 2025 Season 2 on at
    RE: Allow post and send only when there's inventory.

    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
    60,969 Super User 2025 Season 2 on at
    RE: Allow post and send only when there's inventory.

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

    pastedimage1674793348833v1.png

  • yaza Profile Picture
    50 on at
    RE: Allow post and send only when there's inventory.

    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
    Inge M. Bruvik Profile Picture
    1,045 Moderator on at
    RE: Allow post and send only when there's inventory.

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

  • Verified answer
    YUN ZHU Profile Picture
    93,222 Super User 2025 Season 2 on at
    RE: Allow post and send only when there's inventory.

    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
    RE: Allow post and send only when there's inventory.

    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 2,828

#2
Sumit Singh Profile Picture

Sumit Singh 2,617

#3
YUN ZHU Profile Picture

YUN ZHU 1,861 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans