SalesOrder.ChangePartNumMaster

Hi,

I created a BPM in Quote.CreateOrder.Post to update the new order and I have a weird situation.

First, I activated the Epicor log to see exactly which BO I have to call if I want to change the part on a line of the new Sales Order whe I did it manually. Two methods were called, ChangePartNumMaster and MasterUpdate. If I look in the Epicor log, the ChangePartNumMaster receive a dataset with the RowMod = “” for my order line. When the ChangePartNumMaster returned with the RowMod = “U” for my order line then a MasterUpdate is called to persist the change in the database.

If, in my BPM, I call the ChangePartNumMaster method with a RowMod = “” on my order line, I received an exception which said that my order line didn’t changed!!!

I tried to set a RowMod=“U” on my order line before calling the ChangePartNumMaster method, it worked but when I called the MasterUpdate method, I received an exception which said the row has been modified by another user…

Regards
Al

        public void CreateWorksheetRecords(int pOrderNum)
        {
            try
            {
                WriteLine(String.Format("Creating worksheet records for order #{0}...", pOrderNum));

                using (SalesOrderSvcContract bo = Ice.Assemblies.ServiceRenderer.GetService<SalesOrderSvcContract>(this.Db))
                {
                    SalesOrderTableset ds = bo.GetByID(pOrderNum);
                    var allOrderDtl = ds.OrderDtl.Where(r => string.IsNullOrEmpty(r.KitFlag))
                                                 .OrderBy(o => o.OrderLine)
                                                 .ToList();

                    foreach (OrderDtlRow oneOrderDtl in allOrderDtl)
                    {
                        Part thePart = this.Db.Part.FirstOrDefault(r => r.Company == oneOrderDtl.Company &&
                                                                        r.PartNum == oneOrderDtl.PartNum &&
                                                                        !string.IsNullOrEmpty(r.SalesKit_c));

                        if (thePart == null)
                        {
                            WriteLine(string.Format("Part \"{0}\" for line #{1} have no saleskit defined in \"PART\" table.", oneOrderDtl.PartNum, oneOrderDtl.OrderLine));
                            continue;
                        }

                        using (var txtScope = Ice.IceDataContext.CreateDefaultTransactionScope())
                        {
                            OrderDtl tmpOrderDtl = new OrderDtl();
                            Epicor.Data.BufferCopy.Copy(oneOrderDtl, tmpOrderDtl);
                            UD103 newUD103 = GetNewUD103(tmpOrderDtl);
                            this.Db.UD103.AddObject(newUD103);
                            this.Db.Validate();

                            CreateFromAsmMtlRecords(newUD103.Key1, oneOrderDtl.QuoteNum, oneOrderDtl.QuoteLine);

                            txtScope.Complete();
                        }

                        try
                        {
                            callContextBpmData.Checkbox01 = true;

                            string replacingPart = thePart.SalesKit_c;
                            bool substitutePartExist = false;
                            bool isPhantom = false;
                            string uomCode = "";
                            string deleteComponentMessage;
                            bool multiplePatch;
                            bool promptToExplodeBOM;
                            string questionString;
                            string warningMessage;
                            string subPartMessage;
                            string explodeBOMerrMessage;
                            string msgType;
                            bool multiSubsAvail;
                            bool runOutQtyAvail;

                            WriteLine(string.Format("Invoking \"ChangePartNumMaster\" for order #{0}, line #{1}, current part \"{2}\", replacing part \"{3}\"...", oneOrderDtl.OrderNum, oneOrderDtl.OrderLine, oneOrderDtl.PartNum, thePart.SalesKit_c));
                            OrderDtlRow orgOrderDtl = Epicor.Data.BufferCopy.Clone<OrderDtlRow>(oneOrderDtl);
                            ds.OrderDtl.Add(orgOrderDtl);
                            oneOrderDtl.RowMod = "U";
                            WriteLine("Before ChangePartNumber");
                            DumpOject(oneOrderDtl);
                            bo.ChangePartNumMaster(ref replacingPart,
                                                   ref substitutePartExist,
                                                   ref isPhantom,
                                                   ref uomCode,
                                                   Guid.Empty,
                                                   "",
                                                   false,
                                                   false,
                                                   false,
                                                   true,
                                                   true,
                                                   true,
                                                   out deleteComponentMessage,
                                                   out questionString,
                                                   out warningMessage,
                                                   out multiplePatch,
                                                   out promptToExplodeBOM,
                                                   out questionString,
                                                   out subPartMessage,
                                                   out explodeBOMerrMessage,
                                                   out msgType,
                                                   out multiSubsAvail,
                                                   out runOutQtyAvail,
                                                   ref ds);
                            WriteLine("After ChangePartNumber");
                            DumpOject(oneOrderDtl);
                            WriteLine("\"ChangePartNumMaster\" invoked.");

                            bool vContinue;
                            string vResponseMsg;
                            string vCreditShipAction;
                            string vDisplayMsg;
                            string vCompliantMsg;
                            string vResponseMsgOrdRel;
                            string vAgingMessage;

                            WriteLine(string.Format("Invoking \"MasterUpdate\" for order #{0} and line #{1}...", oneOrderDtl.OrderNum, oneOrderDtl.OrderLine));
                            WriteLine("Before MasterUpdate");
                            DumpOject(oneOrderDtl);
                            oneOrderDtl.RowMod = "U";

                            bo.MasterUpdate(true,
                                            true,
                                            "OrderDtl",
                                            oneOrderDtl.CustNum,
                                            oneOrderDtl.OrderNum,
                                            false,
                                            out vContinue,
                                            out vResponseMsg,
                                            out vCreditShipAction,
                                            out vDisplayMsg,
                                            out vCompliantMsg,
                                            out vResponseMsgOrdRel,
                                            out vAgingMessage,
                                            ref ds);
                            WriteLine("After MasterUpdate");
                            DumpOject(oneOrderDtl);
                            WriteLine("\"MasterUpdate\" invoked.");
                        }
                        finally
                        {
                            callContextBpmData.Checkbox01 = false;
                        }
                    }
                }

                WriteLine(String.Format("Worksheet records for order #{0} created.", pOrderNum));
            }
            catch (Exception e)
            {
                WriteLine(e.ToString());
                throw (e);
            }
        }

Not sure this helps, but in some cases I’ve found in a BPM I have to call one Method and then immediately after call the Update Method to replicate. Here is an example from another post:

image

I prefer to use widgets instead of custom code when possible. In my experience Epicor Widget auto generated code seems to upgrade more reliably than manually written code.

Hi Rick_Bird,

thank’s for your time :slight_smile: I call an external BPM form specifics treatments that’s why I do not use widgets.

Regards
Al