Skip to main content
Answer

PXSelector static where clause

  • September 13, 2021
  • 3 replies
  • 1096 views

I have added a field to the existing SOOrder DAC in order to carry a ReasonCode.. But I only want to select records from the ReasonCode where the Usage field is equal to ‘A’

Here is my selector code to display the ReasonCodeID and Descr fields..

[PXSelector(typeof(Search<ReasonCode.reasonCodeID, Where<ReasonCode.usage, Equal<'A'>>>), typeof(ReasonCode.reasonCodeID), typeof(ReasonCode.descr))]
 

 

But this is the error:

\App_RuntimeCode\PX_Objects_SO_SOOrder_extensions.cs(36): error CS1031: Type expected

Best answer by Gabriel Michaud

Hi @ryanmoon32,

You cannot include scalar values directly in BQL queries. You need to use a constant class, like this one:

public class myConstant : Constant<string> { public myConstant() : base(“A”) { } }

It just so happens there’s already a set of constants defined for reason code usage in the ReasonCodeUsages class; you don’t need to redefine it. Here’s how it should look:

[PXSelector(typeof(Search<ReasonCode.reasonCodeID, Where<ReasonCode.usage, Equal<ReasonCodeUsages.adjustment>>>), typeof(ReasonCode.reasonCodeID), typeof(ReasonCode.descr))]

 

3 replies

Gabriel Michaud
Captain II
Forum|alt.badge.img+11

Hi @ryanmoon32,

You cannot include scalar values directly in BQL queries. You need to use a constant class, like this one:

public class myConstant : Constant<string> { public myConstant() : base(“A”) { } }

It just so happens there’s already a set of constants defined for reason code usage in the ReasonCodeUsages class; you don’t need to redefine it. Here’s how it should look:

[PXSelector(typeof(Search<ReasonCode.reasonCodeID, Where<ReasonCode.usage, Equal<ReasonCodeUsages.adjustment>>>), typeof(ReasonCode.reasonCodeID), typeof(ReasonCode.descr))]

 


  • Author
  • Freshman I
  • September 13, 2021

Thanks @Gabriel Michaud 
For future reference, where would that class for the constant go inside of my customization project?

Code - Create Code File - New Graph or Code File?


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • September 14, 2021

Hi @ryanmoon32  Yes.

As per standard practice, you need to create the separate class file (Constants.cs), where you can maintain all constants of your project and access it from here.