PreventNegativeInventory() : Boolean
CASE
"Prevent Negative Inventory"
OF
"Prevent Negative Inventory"::Yes:
EXIT(
TRUE
);
"Prevent Negative Inventory"::No:
EXIT(
FALSE
);
"Prevent Negative Inventory"::Default:
BEGIN
InventorySetup.GET;
EXIT
(InventorySetup."Prevent Negative Inventory");
END
;
END
;
But this is not the complete one, we need to find other places where this function is been called. So I went back to “Statical Prism” and search for the PreventNegativeInventory function usage.
As shown in the above picture PreventNegativeInventory function is called from Item Ledger Entry Table
VerifyOnInventory()
IF
NOT
Open
THEN
EXIT
;
IF
Quantity >= 0
THEN
EXIT;
CASE
"Entry Type"
OF
"Entry Type"::Consumption,"Entry Type"::"Assembly Consumption","Entry Type"::Transfer:
ERROR(IsNotOnInventoryErr,"Item No.");
ELSE BEGIN
Item.GET("Item No.");
IF
Item.PreventNegativeInventory
THEN
ERROR(IsNotOnInventoryErr,"Item No.");
END
;
END
;
As in the code this is not the complete code, to find out the missing part open up the “Statical Prism” and search for VerifyOnInventory function usage.
There you go, In the “Item Jnl.-Post Line” Code Unit under InsertItemLedgEntry function it calls for VerifyOnInventory function and it trigger the entire process. Following is the function code.
LOCAL InsertItemLedgEntry(VAR ItemLedgEntry : Record "Item Ledger Entry";TransferItem : Boolean)
WITH
ItemJnlLine
DO BEGIN
IF
ItemLedgEntry.Open
THEN BEGIN
ItemLedgEntry.VerifyOnInventory;
IF NOT
(("Document Type"
IN
["Document Type"::"Purchase Return Shipment","Document Type"::"Purchase Receipt"])
AND
("Job No." <> ''))
THEN
IF
(ItemLedgEntry.Quantity < 0)
AND
(ItemTrackingCode."SN Specific Tracking"
OR
ItemTrackingCode."Lot Specific Tracking")
THEN
ERROR
(Text018,"Serial No.","Lot No.","Item No.","Variant Code");
Hope you got the code behind the prevent negative inventory option in Microsoft Dynamics NAV.
2 comments
I found this article easy to understand and very helpful. Can’t wait to see the other posts. Thank you for sharing!
Glad it helped.