Skip to main content
Answer

Overriding PXSelectOrderBy Sorting

  • March 4, 2022
  • 7 replies
  • 567 views

In 2020 R1, there were some screens (i.e. Customer Details, Inventory Allocation) where the results grid sorted ascending (oldest date first).  Acumatica changed this in 2021 R1 to sort descending.  Below is a snippit from the ARDocumentEnq graph where the code that was changed and I cant figure out a way to override the PXSelectOrderBy statement.  The Documents view is what is feeding the grid data.  I know the simplest thing to do is to resort the grid by clicking on the header, but our users have not had to do this for so long that they asked to see if there was a way to override this.  Can anyone let me know if you know how to get past this.

Thanks Everyone

 

#region Selects
        public PXFilter<ARDocumentFilter> Filter;
        [PXFilterable]
        public PXSelectOrderBy<ARDocumentResult, OrderBy<Desc<ARDocumentResult.docDate>>> Documents;
        public PXSetup<ARSetup> ARSetup;
        public PXSetup<Company> Company;

#endregion

Best answer by Naveen Boga

Hi, @mgygi76  Sorry, I have NOT verified the above code, and even I’m facing the same issue.

Can you please try with the code and verify.

 public class ARDocumentEnqExt : PXGraphExtension<ARDocumentEnq>
{
public PXSelectOrderBy<ARDocumentResult, OrderBy<Asc<ARDocumentResult.docDate>>> Documents;



public delegate IEnumerable documentsDelegate();
[PXOverride]
public IEnumerable documents(documentsDelegate baseDelegate)
{
foreach (ARDocumentResult row in baseDelegate())
{
var foundRow = (ARDocumentResult)Base.Documents.Cache.Locate(row);
yield return row;
}
}
}

 

I just verified from my end and it seems it is working!!

7 replies

praveenpo
Semi-Pro III
Forum|alt.badge.img+3
  • Semi-Pro III
  • March 4, 2022

Hi @mgygi76,

Have the same Bql with changing order by with same view Name in extension graph.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • March 4, 2022

@mgygi76  If you wanted to see in the ascending order like in the old version 20 R1, it is not required for any overriding of PXSelectorOrderBy<>.

It requires a small piece of customization that you need to extend the “ARDocumentEnq” graph and have the same view with ascending order like below. 

 

    public class ARDocumentEnqExt : PXGraphExtension<ARDocumentEnq>
{
[PXFilterable]
public PXSelectOrderBy<ARDocumentResult, OrderBy<Asc<ARDocumentResult.docDate>>> Documents;
}

 

Hope this helps!


  • Author
  • Freshman I
  • March 4, 2022

I did try this and we are on the right track, however now the grid will not filter when you use the selectors on the form.  It also now pre-populates the grid with all results, instead of waiting for the filters to be populated first.  Any thoughts?

 

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • March 4, 2022

Hi, @mgygi76  Sorry, I have NOT verified the above code, and even I’m facing the same issue.

Can you please try with the code and verify.

 public class ARDocumentEnqExt : PXGraphExtension<ARDocumentEnq>
{
public PXSelectOrderBy<ARDocumentResult, OrderBy<Asc<ARDocumentResult.docDate>>> Documents;



public delegate IEnumerable documentsDelegate();
[PXOverride]
public IEnumerable documents(documentsDelegate baseDelegate)
{
foreach (ARDocumentResult row in baseDelegate())
{
var foundRow = (ARDocumentResult)Base.Documents.Cache.Locate(row);
yield return row;
}
}
}

 

I just verified from my end and it seems it is working!!


  • Author
  • Freshman I
  • March 4, 2022

Thank you so much that did the trick!


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • March 4, 2022

Awesome @mgygi76  Thanks for sharing the update!


Forum|alt.badge.img
  • Freshman I
  • August 2, 2025

Boosting for visibility, ​@Naveen Boga to the rescue as always!

I ended up using a similar approach to get some dynamic date math into a view definition on a custom graph. Does anyone have a better way to get only results from the last day (or week/month/year) in a BQL query? From what I have seen, it is not possible, since BQL does not support runtime calculations?

Below is my workaround based on the approach in this thread, but I would not want to use this for a large result set...If anyone has a better solution, I would love to know about it!

    public PXSelect<AKSOClonerHist,

                Where<AKSOClonerHist.orderNbr, Equal<Current<SOOrder.orderNbr>>>,

                  //removing filter, as we can apply other conditions in the override.

                  //And<AKSOClonerHist.isCreatedSuccessfully, Equal<False>>>,

                OrderBy<Asc<AKSOClonerHist.isCreatedSuccessfully, Desc<AKSOClonerHist.lastModifiedDateTime>>>> DetailsView;

   

 

    public PXSelect<AKSOClonerHist,

                Where<AKSOClonerHist.orderNbr, Equal<Current<SOOrder.orderNbr>>>,

                  //And<AKSOClonerHist.isCreatedSuccessfully, Equal<False>>>,

                OrderBy<Asc<AKSOClonerHist.isCreatedSuccessfully, Desc<AKSOClonerHist.lastModifiedDateTime>>>> FilteredDetailsView;

 

    [PXOverride]

    public IEnumerable detailsView()

    {

      DateTime threshold = PXTimeZoneInfo.Now.AddDays(-1);

 

      foreach (AKSOClonerHist row in FilteredDetailsView.Select())

      {

        if (row.IsCreatedSuccessfully == true && row.LastModifiedDateTime < threshold)

        {

          yield break;

        }

        yield return row;

      }

    }