Axapta freeze on salesline inserts

hi,

in my company which sells engine & parts, if a customer wants to buy an engine, he has to trade-in the old engine.The price of the new engine is calculated as if the customer will bring his old engine. To make sure that he returns the old engine, a deposit is taken from him and returned later.

The sales program recognises the item as trade-in and create a deposit line on this order. It also creates a reciprocal sales order with 3 lines for balancing return of deposit money.

This code runs in a class within transaction block.

The problem I have is, when the salesman hits the OK button to run this class, Axapta freezes. On the server side, memory use of the program session will grow to over 1G. I have to kill the session and restart AOS.

Below is the code block. I wonder whether it is the usage of same table buffer or progress.inccount() inside the transaction block that is the cause. I cannot replicate the problem in test system as it doesn’t have the same load as live. Iam thinking of setting up different table buffers for each line record and removing progress.inccount() from inside the transaction block and putting it outside.

I will appreciate any clue for this problem.

Here is the misbehaving code.

ttsbegin;

progress.incCount();

localSalesQty = salesLine.SalesQty;
//create deposit line on the original order
salesLineLocal.ItemId = depositItemId;
salesLineLocal.SalesId = salesTable.SalesId;
salesLineLocal.SalesQty = localSalesQty;
salesLineLocal.initFromInventTable(salesLineLocal.inventTable());
salesLineLocal.SalesPrice = depositAmount;
salesLineLocal.lineAmount = salesLineLocal.calcLineAmountForced();
salesLineLocal.createLine(true,true,false,true,false,false,false);

progress.incCount();
//create new sales order
//if there is already trade-in salesorder in reference field - use this order for creating lines
if (salesTable.AST_TradeInReference && salestable::exist(salesTable.AST_TradeInReference))
{
salesTableLocal = SalesTable::find(salesTable.AST_TradeInReference);
newSalesId = salesTableLocal.SalesId;
} else
{
salesTableLocal.salesStatus = SalesStatus::Backorder;
salesTableLocal.salesType = SalesTable.SalesType;
salesTableLocal.SalesTaker = SalesTable.SalesTaker;
salesTableLocal.SalesResponsible = SalesTable.SalesResponsible;
salesTableLocal.initValue();
numberSequenceCode = SalesParameters::numRefSalesId().NumberSequence;
numberSeq = NumberSeq::newGetNumFromCode(numberSequenceCode);
salesTableLocal.salesId = numberSeq.num();
newSalesId = salesTableLocal.salesId;
salesTableLocal.custAccount = custAccount;
salesTableLocal.initFromCustTable();
salesTableLocal.DeliveryDate = expectedReturnDate;
salesTableLocal.AST_TradeInReference = salesTable.SalesId;
salesTableLocal.AST_TradeIn = NoYes::Yes;
salesTableLocal.insert();
this.copyDeliveryAddress(salesTable,salesTableLocal);
}
progress.incCount();
//create new line 1
salesLineLocal.clear();
salesLineLocal.ItemId = tradeInItemId;
inventDim.InventColorId = inventColorId;
inventDim.InventSizeId = inventSizeId;
inventDim.InventLocationId = inventLocationId;
salesLineLocal.SalesId = salesTableLocal.SalesId;
salesLineLocal.initFromSalesTable(salesTableLocal);
salesLineLocal.initFromInventTable(salesLineLocal.inventTable());
salesLineLocal.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
salesLineLocal.SalesQty = -localSalesQty;
salesLineLocal.SalesPrice = 0.00;
salesLineLocal.lineAmount = salesLineLocal.calcLineAmountForced();
salesLineLocal.createLine(true,false,false,true,false,false,false);

progress.incCount();
//create new line 2
salesLineLocal.clear();
salesLineLocal.ItemId = depositItemId;
salesLineLocal.SalesId = salesTableLocal.SalesId;
salesLineLocal.initFromInventTable(salesLineLocal.inventTable());
salesLineLocal.SalesQty = -localSalesQty;
salesLineLocal.SalesPrice = depositAmount;
salesLineLocal.lineAmount = salesLineLocal.calcLineAmountForced();
salesLineLocal.createLine(true,true,false,true,false,false,false);

progress.incCount();
//create new line 3
salesLineLocal.clear();
salesLineLocal.ItemId = surchargeItemId;
salesLineLocal.SalesId = salesTableLocal.SalesId;
salesLineLocal.initFromInventTable(salesLineLocal.inventTable());
salesLineLocal.SalesQty = localSalesQty;
salesLineLocal.SalesPrice = 0.00;
salesLineLocal.lineAmount = salesLineLocal.calcLineAmountForced();
salesLineLocal.createLine(true,true,false,true,false,false,false);

//update link on old sales record to new sales record
salesTableLocal = SalesTable::find(salesTable.SalesId,true);
salestableLocal.AST_TradeInReference = newSalesId;
salestableLocal.update();

ttscommit;

Sounds exactly like an neverending loop, but since you don’t have any loops… can you debug with breakpoints?