Solved

Trouble w/ Overriding Actions

  • 19 July 2022
  • 2 replies
  • 117 views

Userlevel 4
Badge +1

Hello, 

I am trying to override the CopyOrderQT function to inject some code after this method runs, however, I can’t seem to figure out what I am doing wrong. Any help would be greatly appreciated.

Original Action:

		public virtual IEnumerable CopyOrderQT(PXAdapter adapter)
{
return CopyOrder(adapter);
}

Overridden Action (giving errors):

        public delegate void CopyOrderQTDelegate(PXAdapter adapter);
[PXOverride]
public virtual IEnumerable CopyOrderQT(PXAdapter adapter, CopyOrderQTDelegate baseMethod)
{
SOOrder order = Base.DocumentProperties.Current;
SOOrderExt orderExt = order.GetExtension<SOOrderExt>();
orderExt.UsrBlyRecalcUnitPrice = true;
cache.Update(order); //I understand that cache doesn't exist but need to update the order. I need to make a view and then execute based on that.
return adapter.Get(); //I keep getting a wrong return type
}

I am still trying to understand how the delegate works, but ultimately from what I gather, my parameters must match the original action’s and the return must match the original return. 

As I mentioned, I want to run the base code and then update a field on the order. Any help or direction would be greatly appreciated.

icon

Best answer by Fernando Amadoz 20 July 2022, 15:52

View original

2 replies

Userlevel 5
Badge +2

@rhooper91 

Are you only aiming to update fields in the destination order?

If so, I’d suggest a different approach as overriding CopyOrderQT() may not be trivial. That method eventually invokes CopyOrderProc() and I am not sure how much flexibility you will have to access the target SOOrder object.

As an alternative, you could try to manage it via event handlers:

Because the new order has references to the source object in SOOrder.OrigOrderType and SOOrder.OrigOrderNbr, you could use those values to

i) identify if the source order is QT, and

ii) get values from the source order and modify them as needed in the target order.

Below is a functional example where I take the original description and concatenate a new value at the end:

  public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
protected virtual void _(Events.FieldUpdated<SOOrder, SOOrder.origOrderNbr> e)
{
SOOrder targetOrder = (SOOrder)e.Row;

if (targetOrder.OrigOrderType != null
&& targetOrder.OrigOrderNbr != null
&& targetOrder.OrigOrderType == "QT"
)
{
//We look for the source order
SOOrder sourceOrder = PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>,
And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>.Select(Base, targetOrder.OrigOrderType, targetOrder.OrigOrderNbr);

if (sourceOrder != null)
{
targetOrder.OrderDesc = sourceOrder.OrderDesc + " Added Descr";
}
}
}
}

 

 

Userlevel 4
Badge +1

Thanks, Fernando-

I ended up doing something similar. I put a flag on the order that controls an event handler. It’s a way to circumvent the code.. not the best, but I don’t want to maintain this functionality every time a new update is released and that’s exactly what I would have to do.

I will keep your suggestion on order reference in my back pocket as that is a really powerful idea.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved