Solved

Problem with orderby clause (BQL)

  • 27 October 2021
  • 1 reply
  • 326 views

Userlevel 2

Hi everyone.

I create a method that get the last value of a table. But the order by desc is not working. I put the code and explain in detail

 In this example. I get a value (and it should be the last, but its the first ever) The “order by” clause its not working.

 

        public int getLastPhaseCode()
{
PXResult<CEPhaseCodes> res =
SelectFrom<CEPhaseCodes>.OrderBy<CEPhaseCodes.phaseCode.Desc>.View.
Select(this).FirstOrDefault();

CEPhaseCodes p = (CEPhaseCodes)res;


return (p != null) ? Convert.ToInt32(p.PhaseCode) : 0;
}

Aditional.

CEPhaseCodes is my DAC/Table

 

Can you help me please!

 

 

icon

Best answer by Naveen Boga 27 October 2021, 06:35

View original

1 reply

Userlevel 7
Badge +17

Hi @eddiedaco  Yes, the above query is NOT working with the Order BY, please use the below code.

I just verified it and getting the expected value by using Order By Clause.

 

   public int getLastPhaseCode()
        {
            CEPhaseCodes p = SelectFrom<CEPhaseCodes>.OrderBy<CEPhaseCodes.phaseCode.Desc>.View.SelectWindowed(Base, 0, 1);

 
            return (p != null) ? Convert.ToInt32(p.PhaseCode) : 0;
        }

 

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