Skip to main content
Answer

How to pass in a parameter to a PXSelectBase

  • October 19, 2023
  • 3 replies
  • 190 views

Joe Schmucker
Captain II
Forum|alt.badge.img+3

I am overriding the Process Shipments screen by adding a custom filter.  

For testing, I created a “Five” class and if I put Five instead of @P.AsInt, it works great. 

In the PXSelectBase command, I am able to put @P.AsInt in the statement, but I don’t know how to pass in my value.  How do I pass in the value to the @P?

This is the “Five” class which returns an integer 5.

    public class Five : PX.Data.BQL.BqlInt.Constant<Five>
    {
        public Five() : base(ICSConstants.Five)
        {
        }
    }

This is the command I am overriding

                                    cmd = new
                                        SelectFrom<SOShipment>.
                                        InnerJoin<INSite>.On<SOShipment.FK.Site>.
                                        InnerJoin<Customer>.On<SOShipment.customerID.IsEqual<Customer.bAccountID>>.SingleTableOnly.
                                        LeftJoin<Carrier>.On<SOShipment.FK.Carrier>.
                                        Where<
                                            SOShipment.confirmed.IsEqual<True>.
                                            And<Match<Customer, AccessInfo.userName.FromCurrent>>.
                                            And<Match<INSite, AccessInfo.userName.FromCurrent>>.
                                            And<Exists<
                                                SelectFrom<SOOrderShipment>.
                                                Where<
                                                    SOOrderShipment.shipmentNbr.IsEqual<SOShipment.shipmentNbr>.
                                                    And<SOOrderShipment.shipmentType.IsEqual<SOShipment.shipmentType>>.
                                                    And<SOOrderShipment.invoiceNbr.IsNull>.
                                                    And<SOOrderShipment.createARDoc.IsEqual<True>>.
                                                    And<SOOrderShipment.shipmentQty.IsLess<@P.AsInt>>>>>>.
                                        View(Base);

If I try to use View.Select(Base, 5) it won’t compile.

Best answer by Naveen Boga

@Joe Schmucker  Have you tried like below?

 

  var cmd = new
SelectFrom<SOShipment>.
InnerJoin<INSite>.On<SOShipment.FK.Site>.
InnerJoin<Customer>.On<SOShipment.customerID.IsEqual<Customer.bAccountID>>.SingleTableOnly.
LeftJoin<Carrier>.On<SOShipment.FK.Carrier>.
Where<
SOShipment.confirmed.IsEqual<True>.
And<Match<Customer, AccessInfo.userName.FromCurrent>>.
And<Match<INSite, AccessInfo.userName.FromCurrent>>.
And<Exists<SelectFrom<SOOrderShipment>.
Where<
SOOrderShipment.shipmentNbr.IsEqual<SOShipment.shipmentNbr>.
And<SOOrderShipment.shipmentType.IsEqual<SOShipment.shipmentType>>.
And<SOOrderShipment.invoiceNbr.IsNull>.
And<SOOrderShipment.createARDoc.IsEqual<True>>.
And<SOOrderShipment.shipmentQty.IsEqual<@P.AsInt>>>>>>.View(Base);


SOShipment result = cmd.Select(5);

 

3 replies

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

@Joe Schmucker  Have you tried like below?

 

  var cmd = new
SelectFrom<SOShipment>.
InnerJoin<INSite>.On<SOShipment.FK.Site>.
InnerJoin<Customer>.On<SOShipment.customerID.IsEqual<Customer.bAccountID>>.SingleTableOnly.
LeftJoin<Carrier>.On<SOShipment.FK.Carrier>.
Where<
SOShipment.confirmed.IsEqual<True>.
And<Match<Customer, AccessInfo.userName.FromCurrent>>.
And<Match<INSite, AccessInfo.userName.FromCurrent>>.
And<Exists<SelectFrom<SOOrderShipment>.
Where<
SOOrderShipment.shipmentNbr.IsEqual<SOShipment.shipmentNbr>.
And<SOOrderShipment.shipmentType.IsEqual<SOShipment.shipmentType>>.
And<SOOrderShipment.invoiceNbr.IsNull>.
And<SOOrderShipment.createARDoc.IsEqual<True>>.
And<SOOrderShipment.shipmentQty.IsEqual<@P.AsInt>>>>>>.View(Base);


SOShipment result = cmd.Select(5);

 


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • October 20, 2023

Hi @Naveen Boga !

Unfortunately, the thing I am overriding is just the part that prepares the command.  It gets executed elsewhere.

 

		public virtual PXSelectBase GetShipmentsSelectCommand(SOShipmentFilter filter, GetShipmentsSelectCommandDelegate baseMethod)
{
PXSelectBase cmd;

string customFilter = string.Empty;

switch (filter.Action)
{
case CreateInvoice:
{
SOShipmentFilterExt ext = PXCache<SOShipmentFilter>.GetExtension<SOShipmentFilterExt>(filter);

ICSProcessShipmentsFilters test = stuff.Current;

if (ext.UsrBatchType != null)
{
customFilter = ext.UsrBatchType.Trim();
}

switch (customFilter)
{
case ICSConstants.QtyLessThan5:
{
cmd = new
SelectFrom<SOShipment>.
InnerJoin<INSite>.On<SOShipment.FK.Site>.
InnerJoin<Customer>.On<SOShipment.customerID.IsEqual<Customer.bAccountID>>.SingleTableOnly.
LeftJoin<Carrier>.On<SOShipment.FK.Carrier>.
Where<
SOShipment.confirmed.IsEqual<True>.
And<Match<Customer, AccessInfo.userName.FromCurrent>>.
And<Match<INSite, AccessInfo.userName.FromCurrent>>.
And<Exists<
SelectFrom<SOOrderShipment>.
Where<
SOOrderShipment.shipmentNbr.IsEqual<SOShipment.shipmentNbr>.
And<SOOrderShipment.shipmentType.IsEqual<SOShipment.shipmentType>>.
And<SOOrderShipment.invoiceNbr.IsNull>.
And<SOOrderShipment.createARDoc.IsEqual<True>>.
And<SOOrderShipment.shipmentQty.IsLess<Five>>>>>>.
View(Base);

break;
}
//more stuff here but removed for brevity

return cmd;
}

Maybe I have to override another one where that command gets executed.  The first override would be to prepare the command and the second override would be to provide the actual value. 

I’ll try to find where in the graph the cmd gets executed and see if it can be overridden.


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • October 20, 2023

@Naveen Boga after looking a little deeper, I don’t think I need to be overriding the code that creates the cmd.  I need to override the method that applies the filters to that cmd.

Thanks for the insight.  FYI, your first answer is correct as it does answer my original question.  This answer WILL help me in the future and it explains how that parameter gets populated in the select command.

THANK YOU NAVEEN.