Skip to main content

Notifications

Announcements

No record found.

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

Allow post and send only when there's inventory.

(0) ShareShare
ReportReport
Posted on by 38

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.

  • yaza Profile Picture
    yaza 38 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.
  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 75,561 Super User 2024 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

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 993 Super User 2024 Season 1 on at
    RE: Allow post and send only when there's inventory.

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

  • yaza Profile Picture
    yaza 38 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
    Mohana Yadav Profile Picture
    Mohana Yadav 60,050 Super User 2024 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

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 75,561 Super User 2024 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

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,354 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans