Prevent Negative Inventory NAV 2013

Code To Prevent Negative Inventory in NAV 2013

Step 1: Open CodeUnit 311 Item-Check Avail. in design mode.
Step 2: Go to function ShowAndHandleAvailabilityPage() Rollback : Boolean
Step 3: Replace the entire function with the code below Start and the bolded italics or add the code within the

// Disable Negative Inventory >>>

// Disable Negative Inventory <<<

block to the existing NAV code within the ShowAndHandleAvailabilityPage() Rollback : Boolean routinue;

Start Below
ShowAndHandleAvailabilityPage() Rollback : Boolean
IF NOT GUIALLOWED THEN
EXIT(FALSE);

FetchCalculation(ItemNo2,UnitOfMeasureCode2,InventoryQty2,GrossReq2,SchedRcpt2,
CurrentQuantity2,CurrentReservedQty2,TotalQuantity2,EarliestAvailDate2);
CheckAvailability.SetValues(ItemNo2,UnitOfMeasureCode2,InventoryQty2,GrossReq2,SchedRcpt2,
CurrentQuantity2,CurrentReservedQty2,TotalQuantity2,EarliestAvailDate2);
Rollback := NOT (CheckAvailability.RUNMODAL = ACTION::Yes);

// Disable Negative Inventory >>>
IF Rollback = FALSE THEN BEGIN
MESSAGE(‘Negative Inventory Not Enabled By System Administrator’);
Rollback := TRUE;
END;
// Disable Negative Inventory <<<


Daniel Duodu-Poku

Hi Daniel,

You didn’t write what this post is about. Do you have any questions about it, or is it just an example you liked to share? [:)]

If it is, then a small comment. Best practice is always to use text constants, not write in code.
Also why not: IF NOT RollBack THEN ?

The developer in me first looked on your code… [;)]

Then it hit me. Even NAV 2013 had the setup that does it for you.

Check out [mention:114ef12b5eb9466ea842f39c52ba7882:e9ed411860ed4f2ba0265705b8793d05]'s post here:

http://mohana-dynamicsnav.blogspot.dk/2013/11/how-to-stopprevent-negative-inventory.html

Although your code is easy to do and implement, then nothing beats a standard setup field that does the same. [:)]

Hi Erik,

Like you said, it is really about an example i wanted to share.

IF NOT RollBack THEN and IF Rollback = FALSE THEN, programmatically are same, its just a matter of style, lol.

Again text constants are the best, but to simplify the example, especially for a novice, i regarded this as a fine approach.

In fact i could have gone further for a setup approach by modifying the inventory setup, then looking the Boolean value from the inventory setup from the code unit, thereby handing the admin total control to turn it on and off.

Regards

Daniel

Hi Erik,

Mohana’s post covers NAV 2013R2, this post is about NAV 2013.

Regards
Daniel

Ahh sure it didn’t get there until 2013 R2… [:)]
But then thank you for sharing. I’m sure a lot of developers will be able to use it.