Hey guys,
I have developed an add-on that updates the prices in the lines of purchase orders. The add-on works correctly, however it seems to crash because of lack of memory. Is there a way to make this more efficient?
The code below runs once for each Purchase Order over a period of one month:
//get lines of specific Purchase Order
string query = "SELECT ItemCode FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry=T1.DocEntry WHERE T0.DocEntry = '" + docEntry + "'";
oRec2.DoQuery(query);
int count = oRec2.RecordCount;
SAPbobsCOM.Documents oPO;
oPO = ((SAPbobsCOM.Documents)(Globals.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseOrders)));
oPO.GetByKey(int.Parse(docEntry));
string query2;
for (int i = 0; i < count; i++)
{
oPO.Lines.SetCurrentLine(i);
string item = oPO.Lines.ItemCode.ToString();
query2 = "SELECT Price FROM ITM1 WHERE ItemCode = '" + item + "' AND PriceList = '" + priceList + "'";
oRec3.DoQuery(query2);
string price = oRec3.Fields.Item("Price").Value.ToString();
oPO.Lines.UnitPrice = double.Parse(convertToRegDecimal(price));
oPO.Lines.Add();
}
oPO.Update();