InsertItemLedgEntry(VAR ItemLedgEntry : Record "Item Ledger Entry";TransferItem : Boolean)
WITH
ItemJnlLine
DO
BEGIN
IF
ItemLedgEntry.Open
THEN BEGIN
IF
(((ItemLedgEntry."Entry Type"
IN
[ItemLedgEntry."Entry Type"::"Negative Adjmt.",
ItemLedgEntry."Entry Type"::Consumption])AND
("Source Type" = "Source Type"::Item))OR
(ItemLedgEntry."Entry Type" = ItemLedgEntry."Entry Type"::Transfer))AND
(ItemLedgEntry.Quantity < 0)
THEN
ERROR
(Text005,ItemLedgEntry."Item No.");
That means all the sales related transactions are allows so the users can sell the goods to a client even if the stocks are not available in the system inventory. This sometimes create lot of inventory related issues in the company. Therefore many companies request partners to block the negative inventory in their system.
How to do it in earlier versions :
Original Code :
InsertItemLedgEntry(VAR ItemLedgEntry : Record "Item Ledger Entry";TransferItem : Boolean)
WITH
ItemJnlLine
DO
BEGIN
IF
ItemLedgEntry.Open
THEN BEGIN
IF
(((ItemLedgEntry."Entry Type"
IN
[ItemLedgEntry."Entry Type"::"Negative Adjmt.",
ItemLedgEntry."Entry Type"::Consumption])AND
("Source Type" = "Source Type"::Item))OR
(ItemLedgEntry."Entry Type" = ItemLedgEntry."Entry Type"::Transfer))AND
(ItemLedgEntry.Quantity < 0)
THEN
ERROR
(Text005,ItemLedgEntry."Item No.");
Modification Required:
You required to add below lines of code to the “InsertItemLedgEntry” function in the “Item Jnl.-Post Line” Code Unit.
// TC 02.201.2016
IF
(ItemLedgEntry.Quantity < 0)
THEN
ERROR
(Text005,ItemLedgEntry."Item No.");
// TC 02.201.2016 End
Once the code is been added, function will be look like below
InsertItemLedgEntry(VAR ItemLedgEntry : Record "Item Ledger Entry";TransferItem : Boolean)
WITH
ItemJnlLine
DO BEGIN
IF
ItemLedgEntry.Open
THEN BEGIN
IF
(((ItemLedgEntry."Entry Type"
IN
[ItemLedgEntry."Entry Type"::"Negative Adjmt.",
ItemLedgEntry."Entry Type"::Consumption])AND
("Source Type" = "Source Type"::Item))OR
(ItemLedgEntry."Entry Type" = ItemLedgEntry."Entry Type"::Transfer))AND
(ItemLedgEntry.Quantity < 0)
THEN
ERROR
(Text005,ItemLedgEntry."Item No.");
// TC 02.201.2016
IF
(ItemLedgEntry.Quantity < 0)
THEN
ERROR
(Text005,ItemLedgEntry."Item No.");
// TC 02.201.2016 End
With the above two lines added to the existing code, Dynamics NAV will provide the required validation to prevent negative inventory.
If you required to give a more dynamics control to the users, you can define a field in the Inventory Setup Table and from that you can write the validation. With that your system administrator can change the condition dynamically.
Result:
In my next blog post I will describe on how to do the prevent negative inventory in the Dynamics NAV 2013 R2, 2015 and 2016 versions.
Please provide your feedback with a comment.