Hi, Readers.
Today I would like to talk briefly about how to show a warning about low inventory on a sales document in Business Central.
When someone enters a quantity for an item on a sales document that exceeds the item’s current inventory level at the location, you might want to let them know by displaying a notification. For example,


There is a standard function to do it.
Choose the Tell Me icon, enter Sales & Receivables Setup, and then choose the related link.

Depending on whether you want to show the warning, turn on or turn off the Stockout Warning toggle.
Stockout Warning
Specifies if a warning is displayed when you enter a quantity on a sales document that brings the item’s inventory level below zero.

After entering the quantity again, the user will see this notification.
The available inventory for item 1896-S is lower than the entered quantity at this location.

Click Show details to open the Availability Check page to view detailed inventory information for this item.

If you don’t want to see this notification, click Don’t show again, or go to My Notifications and disable Item availability is low.


Show a warning when someone creates a sales order or sales invoice for an item that is out of stock.

You can also add some conditions to show a warning about low inventory only for certain items.



The notification is just to inform them of the potential problem, and doesn’t prevent them from creating the order or posting the order. If you just want to prohibit users from posting orders, it is recommended to use the following method, which will prompt an error when posting.
Dynamics 365 Business Central: Prevent Negative Inventory

If you want to prohibit users from adding sales lines with low inventory, this can only be done through customization as of now.
You can refer to the standard processing: codeunit 311 “Item-Check Avail.” -> procedure ShowWarning

For example,


Test video:
Source code: Github (Please note that the source code is for reference only, you can improve it according to your own needs)
codeunit 50112 ItemAvailabilityHandler
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Item-Check Avail.", OnShowWarningOnAfterCalculate, '', false, false)]
local procedure "Item-Check Avail._OnShowWarningOnAfterCalculate"(ItemNo: Code[20]; ItemNetChange: Decimal; InitialQtyAvailable: Decimal)
begin
if InitialQtyAvailable + ItemNetChange < 0 then
Error('The available inventory for item %1 is lower than the entered quantity at this location.', ItemNo);
end;
}
Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント