Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding items to an existing order - Operation is not allowed error 2

Status
Not open for further replies.

oxie18

Programmer
Feb 17, 2015
40
CA
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?

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.
 
Always change your .Order back to 0 before updating or inserting records. See if that helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top