Skip to main content
Solved

Trouble w/ Overriding Actions


Forum|alt.badge.img+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.

Best answer by Fernando Amadoz

@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";
            }            
          }
    }
  }

 

 

View original
Did this topic help you find an answer to your question?

2 replies

Fernando Amadoz
Jr Varsity I
Forum|alt.badge.img+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";
            }            
          }
    }
  }

 

 


Forum|alt.badge.img+1
  • Author
  • Varsity III
  • 64 replies
  • July 21, 2022

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings