Hi,
I'm trying to add a new line item for an existing order but I'm getting an "Operation not allowed" error on OEORDD.Insert() line. Can anyone please check my code?
Thanks in advance.
I'm trying to add a new line item for an existing order but I'm getting an "Operation not allowed" error on OEORDD.Insert() line. Can anyone please check my code?
Code:
public string EditOrder(Order order, string orderID)
{
string result = "";
bool orderExists = OrderExists(orderID);
try
{
if (ConnectToSession(Properties.Settings.Default.AccpacUser, Utils.Decrypt(Properties.Settings.Default.AccpacPwd), Properties.Settings.Default.AccpacDB))
{
if (OpenAndComposeOEViews())
{
if (orderExists)
{
OEORDH.Order = 1; //ORDNUMBER
OEORDHFields.FieldByName["ORDNUMBER"].set_Value(orderID);
OEORDH.Read();
if (!string.IsNullOrEmpty(order.OrderDescription))
OEORDHFields.FieldByName["DESC"].set_Value(order.OrderDescription);
if (!string.IsNullOrEmpty(order.OrderReference))
OEORDHFields.FieldByName["REFERENCE"].set_Value(order.OrderReference);
foreach (OrderItem oItem in order.OrderItems)
{
OEORDD.Order = 1; //ORDUNIQ, DETAILNUM
//OEORDDFields.FieldByName["ORDUNIQ"].set_Value(OEORDHFields.FieldByName["ORDUNIQ"].get_Value());
//OEORDDFields.FieldByName["DETAILNUM"].set_Value(oItem.LineNo);
OEORDD.Browse("ORDUNIQ=" + OEORDHFields.FieldByName["ORDUNIQ"].get_Value() + " AND DETAILNUM=" + oItem.LineNo, true);
if (OEORDD.Fetch()) //line exists
{
OEORDDFields.FieldByName["QTYORDERED"].set_Value(oItem.OrderQty);
OEORDD.Update();
}
else //new line item
{
OEORDD.GoBottom();
OEORDD.RecordGenerate(false);
//OEORDD.RecordCreate(tagViewRecordCreateEnum.VIEW_RECORD_CREATE_DELAYKEY);
OEORDDFields.FieldByName["ITEM"].set_Value(oItem.ItemID);
OEORDDFields.FieldByName["PROCESSCMD"].PutWithoutVerification("1");
OEORDD.Process();
OEORDDFields.FieldByName["DESC"].set_Value(oItem.ItemDescription);
OEORDDFields.FieldByName["PRICELIST"].set_Value("DEFAUL"); //for testing only
//OEORDDFields.FieldByName["UNITPRICE"].set_Value("10"); //for testing only
OEORDDFields.FieldByName["QTYORDERED"].set_Value(oItem.OrderQty);
OEORDD.Insert(); //this throws an error
}
}
OEORDH.Update();
result = OEORDHFields.FieldByName["ORDNUMBER"].get_Value().ToString() + " updated.";
CloseOEViews();
}
}
}
}
catch (Exception ex)
{
result = "Failed to update order.";
AccpacErrorHandler(ex);
}
finally
{
CloseSession();
}
return result;
}
Thanks in advance.