Solved

Changing SOOrder Sort sequence in SOCreateShipment


Userlevel 2
Badge

In SO Process Orders, I am trying to change the sort sequence for SO’s displayed. The default is by Order number, but I want it sorted by RequestDate instead, when the list is initially displayed. I created a SOCreateShipment extension, and extended the BuildCommandCreateShipment() method:

  public class SOCreateShipment_Extension : PXGraphExtension<SOCreateShipment>
  {
    #region Event Handlers
    public delegate PXSelectBase<SOOrder> BuildCommandCreateShipmentDelegate(SOOrderFilter filter);
    [PXOverride]
    public PXSelectBase<SOOrder> BuildCommandCreateShipment(SOOrderFilter filter, BuildCommandCreateShipmentDelegate baseMethod)
    {
      PXTrace.WriteInformation("BuildCommandCreateShipment() started from extension");
      // Add Order By Request Date to default view
      PXSelectBase<SOOrder> extFilter = baseMethod(filter);
      extFilter.OrderByNew<OrderBy<Asc<SOOrder.requestDate>>>();
      string errmsg = "extFilter value is: " + extFilter.ToString();
      PXTrace.WriteInformation(errmsg);
      return extFilter;
    }

The trace Information does show that the ‘Order By’ is added to the DataView. I can also execute the Trace’s generated SQL in Microsoft SQL Studio, and I do see the order rows sorted by RequestDate. 

However, the rows still display to the form in Order Number sequence. 

What am I missing?

Using version 2021 R2 Build 21.203.0026

icon

Best answer by rdennisj57 31 August 2022, 16:25

View original

11 replies

Userlevel 4
Badge +2

While you are no doubt adding the records to the cache in the order that you intend, the UI is defaulting to the ordering stipulated (or defaulted) by the view.  I would try overriding the View definition and adding the orderby clause.

Userlevel 2
Badge

HI Patrick, thank you for the suggestion. I made changes you recommended, and overrode the SOCreateShipment method BuildCommandCreateShipment(). but I am still not seeing the order data sorted by the SOOrder.RequestDate. It is still sorting on the display based on SOOrder DAC primary key. Here is the overriden method call in SOCreateShipment_Extension:

    public PXSelectBase<SOOrder> BuildCommandCreateShipment(SOOrderFilter filter, BuildCommandCreateShipmentDelegate baseMethod)
    {

            // Approach 2 - Replace entire method, and add OrderBy to the View
            SOCreateShipment baseGraph = Base;
            PXSelectBase<SOOrder> cmd = new PXSelectJoinGroupBy<SOOrder,
                LeftJoin<Carrier, On<SOOrder.shipVia, Equal<Carrier.carrierID>>,
                InnerJoin<SOShipmentPlan,
                    On<SOOrder.orderType, Equal<SOShipmentPlan.orderType>,
                        And<SOOrder.orderNbr, Equal<SOShipmentPlan.orderNbr>>>,
                InnerJoin<INSite, On<INSite.siteID, Equal<SOShipmentPlan.siteID>>,
                LeftJoin<SOOrderShipment,
                    On<SOOrderShipment.orderType, Equal<SOShipmentPlan.orderType>,
                        And<SOOrderShipment.orderNbr, Equal<SOShipmentPlan.orderNbr>,
                        And<SOOrderShipment.siteID, Equal<SOShipmentPlan.siteID>,
                        And<SOOrderShipment.confirmed, Equal<boolFalse>>>>>,
                LeftJoinSingleTable<Customer, On<SOOrder.customerID, Equal<Customer.bAccountID>>>>>>>,
                Where<SOShipmentPlan.inclQtySOBackOrdered, Equal<short0>, And<SOOrderShipment.shipmentNbr, IsNull,
                    And<SOOrder.status, NotEqual<SOOrderStatus.shipping>,
                    And2<Where<Customer.bAccountID, IsNull, Or<Match<Customer, Current<AccessInfo.userName>>>>,
                    And<Match<INSite, Current<AccessInfo.userName>>>>>>>,
                Aggregate<
                    GroupBy<SOOrder.orderType,
                    GroupBy<SOOrder.orderNbr,
                    GroupBy<SOOrder.approved>>>>,
                OrderBy<Asc<SOOrder.requestDate>>>(baseGraph);

            string errmsg = "cmd value is: " + cmd.ToString();
            PXTrace.WriteInformation(errmsg);

            if (filter.SiteID != null)
                cmd.WhereAnd<Where<SOShipmentPlan.siteID, Equal<Current<SOOrderFilter.siteID>>>>();

            if (filter.DateSel == "S")
            {
                if (filter.EndDate != null)
                    cmd.WhereAnd<Where<SOShipmentPlan.planDate, LessEqual<Current<SOOrderFilter.endDate>>>>();

                if (filter.StartDate != null)
                {
                    cmd.WhereAnd<Where<SOShipmentPlan.planDate, GreaterEqual<Current<SOOrderFilter.startDate>>>>();
                }

                filter.DateSel = string.Empty;
            }

            return cmd;
        }

 

The SOCreateShipment program uses a delegate method to generate the Data View. Could that be the reason the OrderBy is not working?

Randy

Userlevel 2
Badge

Attached is the trace that was generated.

Userlevel 4
Badge +2

I am talking about overriding the Orders view definition

Userlevel 2
Badge

Sorry, I guess I’m confused. I was thinking this IS the View definition? The only other reference I see in SOCreateShipment for ‘Orders’ is:

    public class SOCreateShipment : PXGraph<SOCreateShipment>
    {
        public PXCancel<SOOrderFilter> Cancel;
        public PXAction<SOOrderFilter> viewDocument;

        public PXFilter<SOOrderFilter> Filter;
        [PXFilterable]
        public PXFilteredProcessing<SOOrder, SOOrderFilter> Orders;

Is this what you are referring to? How would I add an OrderBy here?

Userlevel 4
Badge +2

https://help-2021r1.acumatica.com/Help?ScreenId=ShowWiki&pageid=7e9c3596-6a89-4580-b509-fe1b77556e5e

Userlevel 2
Badge

I made this redefinition of the DataView (original is above in Red):

    public PXFilteredProcessing<SOOrder, SOOrderFilter,
              Where<SOOrder.status, NotEqual<SOOrderStatus.shipping>>,
              OrderBy<Asc<SOOrder.requestDate>>> Orders;

This DOES now show the list of orders in RequestDate order. However,

  1. I only wanted to supply the ‘OrderBy’ clause, but it required me to also supply the ‘Where’ clause.
  2. When I supply the Where clause, the actual filter is overriding the Where clause defined in the Delegate view (ie the ‘orders() method’. Is there a way to add only an ‘OrderBy’? 
Userlevel 4
Badge +2

Not that I know of:  Where<True, IsEqual<True» always works ;)

Userlevel 4
Badge +2

You could also override the view delegate and just add an orderby clause 

https://help-2021r1.acumatica.com/(W(3))/Help?ScreenId=ShowWiki&pageid=d50ee403-753c-41b9-b996-90dad1f2e98e

Userlevel 2
Badge

Thank you Patrick!

Userlevel 2
Badge

Patrick, 

After following your suggestions, and redefining the DataView in SOCreateShipment_Extension, I have discovered that the view delegate (defined in the base SOCreateShipment as orders()) logic is no longer being executed, when using the Visual Studio debugger. If I remove my redefinition, and debug again, the delegate view method IS BEING executed.  Does this mean that if you redefine the data view, you must ALSO redefine the view delegate?

Here again is the Data View redefinition in my extension:

  public class SOCreateShipment_Extension : PXGraphExtension<SOCreateShipment>
  {
    #region Data Views
    [PXFilterable]
    public PXFilteredProcessing<SOOrder, SOOrderFilter,
              Where<True, Equal<True>>,
              OrderBy<Asc<SOOrder.requestDate>>> Orders;
    #endregion

    #region isActive
    public static bool IsActive()
    {
       return true;
    }
    #endregion
  }

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