Skip to main content
Answer

PXRestrictor to select a customer belonging to a specific Customer Class

  • August 2, 2024
  • 3 replies
  • 153 views

kevlynch
Jr Varsity II
Forum|alt.badge.img

Hi,

I’m working on my first customization adding a new table / DAC with a foreign key linking to Customers.

The need is to restrict the selection of the customer to only customers belonging to a specific class.

This is what I currently have in my DAC definition for this field:
 

        #region CustomerID
[PXRestrictor(typeof(Where<Customer.customerClassID, Equal<Customer.customerClassID.Contains<"SPECIAL">>>), "Not a Special Customer")]
[Customer]
[PXDefault]
public virtual int? CustomerID{ get; set; }
public abstract class customerID :
PX.Data.BQL.BqlInt.Field<customerID>
{ }
#endregion

I’m getting a “CS1031: Type expected” error on “SPECIAL”. I can’t find an example of creating a PXRestrictor condition that isn’t based around a boolean, null check or comparison to a value from a matching field on this DAC. Is there a way I can create this sort of hard-coded filter?

Appreciate any guidance here.

Best answer by Vignesh Ponnusamy

Hi @kevlynch,

Try defining the BQL parameter like below and use the BQLString object in the BQL query,

public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SPECIAL") { }
}

//Update BQL query like below

[PXRestrictor(typeof(Where<Customer.customerClassID, Equal<Customer.customerClassID.Contains<custClass>>>), "Not a Special Customer")]

Hope that helps.! Feel free to post back if you have any questions.

3 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @kevlynch,

Try defining the BQL parameter like below and use the BQLString object in the BQL query,

public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SPECIAL") { }
}

//Update BQL query like below

[PXRestrictor(typeof(Where<Customer.customerClassID, Equal<Customer.customerClassID.Contains<custClass>>>), "Not a Special Customer")]

Hope that helps.! Feel free to post back if you have any questions.


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi @kevlynch,

You cannot include scalar values directly in BQL queries. You need to use a constant class like @Vignesh Ponnusamy suggested above to use it in PXRestrictor attribute.


kevlynch
Jr Varsity II
Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • August 16, 2024

Hi @kevlynch,

Try defining the BQL parameter like below and use the BQLString object in the BQL query,

public class custClass : PX.Data.BQL.BqlString.Constant<custClass>
{
public custClass() : base("SPECIAL") { }
}

//Update BQL query like below

[PXRestrictor(typeof(Where<Customer.customerClassID, Equal<Customer.customerClassID.Contains<custClass>>>), "Not a Special Customer")]

Hope that helps.! Feel free to post back if you have any questions.

Hi Vignesh,

It took me a little while to be able to get back to this to implement your suggestion. It worked great with a small tweak to the PXRestrictor line :

[PXRestrictor(typeof(Where<Customer.customerClassID, Equal<custClass>>), "Not a Special Customer")]

Looks like I need to dive deeper into BQL.

 

Thank you so much for your help!