Adding additional filter field on process shipments

1.1k views Asked by At

I have added a new custom field to SOShipment and SOShipmentFilter. I am trying to use it to filter the grid for Process Shipments and I am having problems with the code. I have done other customizations where I have extended code but I was able to call the baseHandler first and then execute my snippet when it returned. However when I override the delegate function, it just sets up a template with a return to baseMethod. When I put my code in to include the new filter field, I get compile errors for undefined fields/references. Do I need to copy all of the original code from the original delegate and include it in my override function? Below is my current override code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using PX.Data;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AR;
using PX.Objects.CM;
using POReceipt = PX.Objects.PO.POReceipt;
using POReceiptLine = PX.Objects.PO.POReceiptLine;
using POLineType = PX.Objects.PO.POLineType;
using PX.Objects;
using PX.Objects.SO;

namespace PX.Objects.SO
{
  public class SOInvoiceShipment_Extension:PXGraphExtension<SOInvoiceShipment>
  {
    #region Event Handlers
    public delegate IEnumerable ordersDelegate();
    [PXOverride]
    public IEnumerable orders(ordersDelegate baseMethod)
    {
      if (filter.usrTruckNbr != null)
      {
        ((PXSelectBase<SOShipment>)cmd).WhereAnd<Where<SOShipment.usrTruckNbr, GreaterEqual<Current<SOShipmentFilter.usrTruckNbr>>>>();
      }
      return baseMethod();
    }
    protected virtual void SOShipmentFilter_UsrTruckNbr_CacheAttached(PXCache cache)
    {

    }
    #endregion
  }
}
1

There are 1 answers

1
Gabriel On BEST ANSWER

cmd is a location variable and you cannot access it from your extension. I see two ways you could achieve the result you want:

  1. Copy the whole delegate function to your extension. This is not ideal because it will have to be verified and updated with every new version of Acumatica.
  2. Filter data on the client side after it is returned from the original delegate but before it is displayed on screen. This is not as efficient as filtering on SQL but at least would remove the need to copy too much code to your extension. Here's a complete sample which will filter the list of shipments to return only documents where shipment quantity is even:

    public class SOInvoiceShipment_Extension : PXGraphExtension<SOInvoiceShipment>
    {
        [PXFilterable]
        public PXFilteredProcessing<SOShipment, SOShipmentFilter> Orders;
    
        protected IEnumerable orders()
        {
            // Filter the list of shipments to return only documents where shipment quantity is even
            foreach (SOShipment shipment in Base.Orders.Select())
            {            
                if(shipment.ShipmentQty % 2 == 0)
                {
                    yield return shipment;
                }
            }
        }
    
        public void SOShipmentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            if (e.Row == null) return;
    
            SOShipmentFilter filter = e.Row as SOShipmentFilter;
            if (filter != null && !string.IsNullOrEmpty(filter.Action))
            {
                Dictionary<string, object> parameters = Base.Filter.Cache.ToDictionary(filter);
                Orders.SetProcessTarget(null, null, null, filter.Action, parameters);
            }
        }
    }
    

In all cases, you should not use PXOverride to override the view delegate; the customization tools unfortunately generate the wrong method signature when you try to override a delegate, and this will be improved. You should refer to the T300 training available here for more information on this type of customization (look for "Declaring or Altering a BLC Data View Delegate).