Items made From Non Stock Being Deleted

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);

NewItem.GET(PurchLine2.“No.”);

TrItemNo := PurchLine2.“No.”;

PurchLine2.“No.” := ’ ';

PurchLine2.MODIFY;

NewItem.DELETE(TRUE);

NonStock.SETRANGE(“Item No.”, TrItemNo);

If NonStock.FIND(’-’) THEN

REPEAT

NonStock.“Item No.” := ’ ';

NonStock.MODIFY;

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

Paul

Paul,

Have you tried remarking out the lines as I suggested?

Hi Connull,

I havent had a chance yet, I will do it later today or first thing tomorrow morning and let you know.

Paul

Hi Connull,

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.

Paul

OK in version 4 it’s slightly different. Look at the function DelNonStockPurch.

DelNonStockPurch(VAR PurchLine2 : Record “Purchase Line”)
IF PurchLine2.Nonstock = FALSE THEN
EXIT;

NewItem.GET(PurchLine2.“No.”);
PurchLine2.“No.” := ‘’;
PurchLine2.MODIFY;

DelNonStockItem(NewItem);

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)
ItemLedgEntry.SETCURRENTKEY(“Item No.”);
ItemLedgEntry.SETRANGE(“Item No.”,Item.“No.”);
IF ItemLedgEntry.FIND(’-’) THEN
EXIT;

SalesLine.SETCURRENTKEY(Type,“No.”);
SalesLine.SETRANGE(Type,SalesLine.Type::Item);
SalesLine.SETRANGE(“No.”,Item.“No.”);
IF SalesLine.FIND(’-’) THEN
EXIT;

PurchLine.SETCURRENTKEY(Type,“No.”);
PurchLine.SETRANGE(Type,PurchLine.Type::Item);
PurchLine.SETRANGE(“No.”,Item.“No.”);
IF PurchLine.FIND(’-’) THEN
EXIT;

ServInvLine.SETCURRENTKEY(Type,“No.”);
ServInvLine.SETRANGE(Type,ServInvLine.Type::Item);
ServInvLine.SETRANGE(“No.”,Item.“No.”);
IF ServInvLine.FIND(’-’) THEN
EXIT;

BOMComp.SETCURRENTKEY(Type,“No.”);
BOMComp.SETRANGE(Type,BOMComp.Type::Item);
BOMComp.SETRANGE(“No.”,Item.“No.”);
IF BOMComp.FIND(’-’) THEN
EXIT;

ProdBOMLine.RESET;
ProdBOMLine.SETCURRENTKEY(Type,“No.”);
ProdBOMLine.SETRANGE(Type,ProdBOMLine.Type::Item);
ProdBOMLine.SETRANGE(“No.”,Item.“No.”);
IF ProdBOMLine.FIND(’-’) THEN
REPEAT
IF ProdBOMHeader.GET(ProdBOMLine.“Production BOM No.”) AND
(ProdBOMHeader.Status = ProdBOMHeader.Status::Certified)
THEN
EXIT;
UNTIL ProdBOMLine.NEXT = 0;

NewItem.GET(Item.“No.”);
IF NewItem.DELETE(TRUE) THEN BEGIN
NonStock.SETRANGE(“Item No.”,Item.“No.”);
IF NonStock.FIND(’-’) THEN BEGIN
REPEAT
NonStock.“Item No.” := ‘’;
NonStock.MODIFY;
UNTIL NonStock.NEXT = 0;
END;
END;

So maybe it’s a simple has not calling this function. Please test and let us know how you get on.

Hi Connull,

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