-1

we have requirement to duplicate the confirm shipment action button for some business work and also need to update some custom fields on confirm shipment long run operation is completed.

Below is my code but while doing cache update i am getting Error: Collection was modified; enumeration operation may not execute.

Please correct me where i am doing wrong

public PXAction<PX.Objects.SO.SOShipment> ConfirmShipment;
        [PXUIField(DisplayName = "Confirm Shipment")]
        [PXButton]
        protected virtual IEnumerable confirmShipment(PXAdapter adapter)
        {
            if (ShipFilter.Current != null)
            {
                var soOrderShip = Base.Document.Current;
                if (soOrderShip != null)
                {
                    var graph = PXGraph.CreateInstance<SOShipmentEntry>();
                    //We are recreating an adapter like the framework would do.
                    var a = new PXAdapter(graph.Document)
                    {
                        Searches = new object[] { soOrderShip.ShipmentNbr }
                    };
                    using (PXTransactionScope ts = new PXTransactionScope())
                    {
                        //Note: Confirm Shipment is Action 1 : 
                        a.Arguments.Add("actionID", 1);
                        PXLongOperation.StartOperation(Base, () => { foreach (SOShipment soShipment in graph.action.Press(a)) ; });
                        //PXLongOperation.WaitCompletion(graph.UID);
                        PXAutomation.CompleteAction(graph);
                        PXLongOperation.WaitCompletion(graph.UID);
                        PXLongOperation.ClearStatus(graph.UID);
                        graph.Document.Cache.SetValueExt<SOShipmentExt.usrKWMXDCTimeStamp>(soOrderShip, Convert.ToDateTime(Convert.ToDateTime(new PX.Data.PXGraph().Accessinfo.BusinessDate).ToShortDateString() + " " + PX.Common.PXTimeZoneInfo.Now.ToLongTimeString()));
                        graph.Document.Cache.SetValueExt<SOShipmentExt.usrKWMXPieceCount>(soOrderShip, Convert.ToDecimal(Base.Document.Current.ShipmentQty));
                        graph.Document.Cache.SetValueExt<SOShipmentExt.usrKWMXEnteredBy>(soOrderShip, this.ShipFilter.Current.EnteredBy);
                        graph.Document.Update(soOrderShip);
                        graph.Save.Press();
                        ts.Complete();
                    }
                }
            }
            return adapter.Get();
        }

Thanks in advance.

BhavyaSri
  • 150
  • 10

1 Answers1

0

You should override the Confirmation routine, execute the Base operation, and then add your code.

Extend existing event

Patrick Chen
  • 1,028
  • 1
  • 6
  • 8
  • Hi, Override ConfirmShipment and calling base method is not working when i click on my new custom button ( as shown above code). the override function is executing when i click on Actions under Confirm Shipment. But here i wont click that button i just press my custom action button and inside i am calling Confirm shipment action – BhavyaSri May 18 '20 at 19:24
  • Read the attached stack answer, you would want to do the 2nd strategy. – Patrick Chen May 18 '20 at 19:54