Skip to main content
Answer

Problem with orderby clause (BQL)

  • October 27, 2021
  • 1 reply
  • 410 views

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!

 

 

Best answer by Naveen Boga

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

 

1 reply

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • October 27, 2021

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