Hi Guys, can anyone shed any light on the logic behind the following senario. One of my clients uses a number of Items created from Non Stock. If the user creates a Purchase Invoice using one of these Items and then realises they have used the wrong Item and then deletes the Purchase Line, the Item is also deleted. I then have to recreate the item from Non Stock. I have looked in the code and it seems to be caused by the codeunit for non stock item management. Can anyone enlighten me as to why the Item should be deleted just because the Purchase Line is deleted. Also, can anyone suggest away of bypassing this delete as it doesnt seem to make sense to delete the item just because the Purchase Line is wrong. Thanks…Paul
What version of Navision are you using?
For 3.70B (GB) …
In the Purchase Line OnDelete( ) trigger, there is a call to the codeunit Nonstock Item Management (5703). It calls the function NonstockPurchDel and this function checks to see if the item has item ledger entries, sales lines, purchase lines and service invoice lines before deleting the item.
My questions are;
(1) If the purchase line has the wrong item on it, just change the item
(2) Just bypass the deleting code in this function - NonstockPurchDel (as below);
TrItemNo := PurchLine2.“No.”;
PurchLine2.“No.” := ’ ';
NonStock.SETRANGE(“Item No.”, TrItemNo);
If NonStock.FIND(’-’) THEN
NonStock.“Item No.” := ’ ';
UNTIL NonStock.NEXT = 0;
Just take out / remark out the last 6 lines. This gets the NonStock record and modifies the Item No.
Try this out and fully test and then let us know if this works how you wanted.
Hope it helps
Sorry, I should have said its version 4 SP2
Have you tried remarking out the lines as I suggested?
I havent had a chance yet, I will do it later today or first thing tomorrow morning and let you know.
CodeUnit 5703 is different in version 4 as the code you pasted in to this thread earlier does not match the code in CU5703 so not sure what I should comment out.
OK in version 4 it’s slightly different. Look at the function DelNonStockPurch.
DelNonStockPurch(VAR PurchLine2 : Record “Purchase Line”)
IF PurchLine2.Nonstock = FALSE THEN
PurchLine2.“No.” := ‘’;
The last line does the call to a function to check the “NewItem” has no item ledger entries, sales lines, purchase lines, service invoice lines and it now also checks to see that it isn’t part of a BOM (BOM Component) and therefore not in production BOM lines.
DelNonStockItem(VAR Item : Record Item)
IF ItemLedgEntry.FIND(’-’) THEN
IF SalesLine.FIND(’-’) THEN
IF PurchLine.FIND(’-’) THEN
IF ServInvLine.FIND(’-’) THEN
IF BOMComp.FIND(’-’) THEN
IF ProdBOMLine.FIND(’-’) THEN
IF ProdBOMHeader.GET(ProdBOMLine.“Production BOM No.”) AND
(ProdBOMHeader.Status = ProdBOMHeader.Status::Certified)
UNTIL ProdBOMLine.NEXT = 0;
IF NewItem.DELETE(TRUE) THEN BEGIN
IF NonStock.FIND(’-’) THEN BEGIN
NonStock.“Item No.” := ‘’;
UNTIL NonStock.NEXT = 0;
So maybe it’s a simple has not calling this function. Please test and let us know how you get on.
thats exactly what I did last night. I //'d the DelNonStockItem(NewItem) function out from within function DelNonStockPurch and it tested out fine. Thanks alot for you help…Paul