Skip to main content
Solved

Filter grid records by custom field

  • April 28, 2024
  • 3 replies
  • 167 views

Forum|alt.badge.img

Hello community,

I want to filter list records in Grid result by a custom field on screen Vendor Prices (APVendorPriceFilterExt.usrShippingTermID)

 

How to override the original select statement and add condition?

Source code of selects Records:

[PXFilterable]
public PXSelectJoin<APVendorPrice,
		LeftJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<APVendorPrice.inventoryID>>,
		LeftJoin<INItemClass, On<INItemClass.itemClassID, Equal<InventoryItem.itemClassID>>,
		LeftJoin<Vendor, On<APVendorPrice.vendorID, Equal<Vendor.bAccountID>>,
		LeftJoin<INSite, On<APVendorPrice.siteID, Equal<INSite.siteID>>>>>>,
		Where2<Where<Vendor.bAccountID, IsNull, Or<Match<Vendor, Current<AccessInfo.userName>>>>,
		And2<Where<InventoryItem.inventoryID, IsNull, Or<Match<InventoryItem, Current<AccessInfo.userName>>>>,
		And2<Where<INItemClass.itemClassID, IsNull, Or<Match<INItemClass, Current<AccessInfo.userName>>>>,
		And2<Where<APVendorPrice.siteID, IsNull, Or<Match<INSite, Current<AccessInfo.userName>>>>,
		And<InventoryItem.itemStatus, NotEqual<INItemStatus.inactive>,
		And<InventoryItem.itemStatus, NotEqual<InventoryItemStatus.unknown>,
		And<InventoryItem.itemStatus, NotEqual<INItemStatus.toDelete>,
		And2<Where<APVendorPrice.vendorID, Equal<Current<APVendorPriceFilter.vendorID>>, Or<Current<APVendorPriceFilter.vendorID>, IsNull>>, 
		And2<Where<APVendorPrice.inventoryID, Equal<Current<APVendorPriceFilter.inventoryID>>, Or<Current<APVendorPriceFilter.inventoryID>, IsNull>>,
		And2<Where<APVendorPrice.siteID, Equal<Current<APVendorPriceFilter.siteID>>, Or<Current<APVendorPriceFilter.siteID>, IsNull>>,
		And2<Where2<Where2<Where<APVendorPrice.effectiveDate, LessEqual<Optional2<APVendorPriceFilter.effectiveAsOfDate>>, Or<APVendorPrice.effectiveDate, IsNull>>, 
		And<Where<APVendorPrice.expirationDate, GreaterEqual<Optional2<APVendorPriceFilter.effectiveAsOfDate>>, Or<APVendorPrice.expirationDate, IsNull>>>>,
		Or<Optional2<APVendorPriceFilter.effectiveAsOfDate>, IsNull>>,
			And<Where2<Where<Current<APVendorPriceFilter.itemClassCD>, IsNull,
					Or<INItemClass.itemClassCD, Like<Current<APVendorPriceFilter.itemClassCDWildcard>>>>,
			And2<Where<Current<APVendorPriceFilter.ownerID>, IsNull,
				Or<Current<APVendorPriceFilter.ownerID>, Equal<InventoryItem.productManagerID>>>,
			And2<Where<Current<APVendorPriceFilter.myWorkGroup>, Equal<boolFalse>,
				 Or<InventoryItem.productWorkgroupID, IsWorkgroupOfContact<CurrentValue<APVendorPriceFilter.currentOwnerID>>>>,
			And<Where<Current<APVendorPriceFilter.workGroupID>, IsNull,
				Or<Current<APVendorPriceFilter.workGroupID>, Equal<InventoryItem.productWorkgroupID>>>>>>>>>>>>>>>>>>>,
		OrderBy<Asc<InventoryItem.inventoryCD,
			Asc<APVendorPrice.uOM, Asc<APVendorPrice.breakQty, Asc<APVendorPrice.effectiveDate>>>>>> Records;

 

Best answer by NicholasBova52

mrthanhkhoi wrote:

hello @Naveen Boga, thank you for your answer but I’m so sorry I didn’t describe it clearly.

The idea is I want to create a new data view delegate and select the same data with some additional filtering or dynamic calculations. However, I don’t want to create a new view as your answer because it has  a risk that Acumatica will update this command in the future.

So I suppose if we could customize the view delegate by creating graph extension, something like this

public class APVendorPriceMaint_Extension : PXGraphExtension<APVendorPriceMaint>
{

    public IEnumerable records()
    {

        // 1. get records return from base statement (the source code of Acumatica)
        // 2. get value of APVendorPriceFilterExt.usrShippingTermID
        // 3. filter records from step 1 by additional condition from step 2

    }
}

 

But I don’t know how to get the records return from original statement in graph extension

 

@mrthanhkhoi  You can achieve this by using the “PXOverride” attribute on the “records()” data view delegate in the graph extension. You’ll then also want to add a method delegate “Func<IEnumerable> baseImpl” as the first parameter of this override method and invoke that to get the enumerable collection of records that you can then filter further. It’ll look something like this:

public class APVendorPriceMaint_Extension : PXGraphExtension<APVendorPriceMaint>
{
    [PXOverride]
    public virtual IEnumerable records(Func<IEnumerable> baseImpl)
    {

        // 1. get records return from base statement (the source code of Acumatica)
        var recordsCollection = baseImpl?.Invoke();

        // 2. get value of APVendorPriceFilterExt.usrShippingTermID
        // 3. filter records from step 1 by additional condition from step 2


        return recordsCollection; // or return whatever modified collection you have at this point
    }
}

You’ll get the collection of records from the base method, then you can filter them however you like, and then return that collection and the grid on the webpage will display your filtered results.

View original
Did this topic help you find an answer to your question?

Naveen Boga
Captain II
Forum|alt.badge.img+19

@mrthanhkhoi  Please use below code and verify

 

[PXFilterable]
public PXSelectJoin<APVendorPrice,
		LeftJoin<InventoryItem, On<InventoryItem.inventoryID, Equal<APVendorPrice.inventoryID>>,
		LeftJoin<INItemClass, On<INItemClass.itemClassID, Equal<InventoryItem.itemClassID>>,
		LeftJoin<Vendor, On<APVendorPrice.vendorID, Equal<Vendor.bAccountID>>,
		LeftJoin<INSite, On<APVendorPrice.siteID, Equal<INSite.siteID>>>>>>,
		Where2<Where<Vendor.bAccountID, IsNull, Or<Match<Vendor, Current<AccessInfo.userName>>>>,
		And2<Where<InventoryItem.inventoryID, IsNull, Or<Match<InventoryItem, Current<AccessInfo.userName>>>>,
		And2<Where<INItemClass.itemClassID, IsNull, Or<Match<INItemClass, Current<AccessInfo.userName>>>>,
		And2<Where<APVendorPrice.siteID, IsNull, Or<Match<INSite, Current<AccessInfo.userName>>>>,
		And<InventoryItem.itemStatus, NotEqual<INItemStatus.inactive>,
		And<InventoryItem.itemStatus, NotEqual<InventoryItemStatus.unknown>,
		And<InventoryItem.itemStatus, NotEqual<INItemStatus.toDelete>,
        And<Vendor.termsID,Equal<Current<APVendorPriceFilterExt.usrShippingTermID>>
		And2<Where<APVendorPrice.vendorID, Equal<Current<APVendorPriceFilter.vendorID>>, Or<Current<APVendorPriceFilter.vendorID>, IsNull>>, 
		And2<Where<APVendorPrice.inventoryID, Equal<Current<APVendorPriceFilter.inventoryID>>, Or<Current<APVendorPriceFilter.inventoryID>, IsNull>>,
		And2<Where<APVendorPrice.siteID, Equal<Current<APVendorPriceFilter.siteID>>, Or<Current<APVendorPriceFilter.siteID>, IsNull>>,
		And2<Where2<Where2<Where<APVendorPrice.effectiveDate, LessEqual<Optional2<APVendorPriceFilter.effectiveAsOfDate>>, Or<APVendorPrice.effectiveDate, IsNull>>, 
		And<Where<APVendorPrice.expirationDate, GreaterEqual<Optional2<APVendorPriceFilter.effectiveAsOfDate>>, Or<APVendorPrice.expirationDate, IsNull>>>>,
		Or<Optional2<APVendorPriceFilter.effectiveAsOfDate>, IsNull>>,
			And<Where2<Where<Current<APVendorPriceFilter.itemClassCD>, IsNull,
					Or<INItemClass.itemClassCD, Like<Current<APVendorPriceFilter.itemClassCDWildcard>>>>,
			And2<Where<Current<APVendorPriceFilter.ownerID>, IsNull,
				Or<Current<APVendorPriceFilter.ownerID>, Equal<InventoryItem.productManagerID>>>,
			And2<Where<Current<APVendorPriceFilter.myWorkGroup>, Equal<boolFalse>,
				 Or<InventoryItem.productWorkgroupID, IsWorkgroupOfContact<CurrentValue<APVendorPriceFilter.currentOwnerID>>>>,
			And<Where<Current<APVendorPriceFilter.workGroupID>, IsNull,
				Or<Current<APVendorPriceFilter.workGroupID>, Equal<InventoryItem.productWorkgroupID>>>>>>>>>>>>>>>>>>>>,
		OrderBy<Asc<InventoryItem.inventoryCD,
			Asc<APVendorPrice.uOM, Asc<APVendorPrice.breakQty, Asc<APVendorPrice.effectiveDate>>>>>> Records;

 


Forum|alt.badge.img

hello @Naveen Boga, thank you for your answer but I’m so sorry I didn’t describe it clearly.

The idea is I want to create a new data view delegate and select the same data with some additional filtering or dynamic calculations. However, I don’t want to create a new view as your answer because it has  a risk that Acumatica will update this command in the future.

So I suppose if we could customize the view delegate by creating graph extension, something like this

public class APVendorPriceMaint_Extension : PXGraphExtension<APVendorPriceMaint>
{

    public IEnumerable records()
    {

        // 1. get records return from base statement (the source code of Acumatica)
        // 2. get value of APVendorPriceFilterExt.usrShippingTermID
        // 3. filter records from step 1 by additional condition from step 2

    }
}

 

But I don’t know how to get the records return from original statement in graph extension


NicholasBova52
Acumatica Employee
Forum|alt.badge.img+1
mrthanhkhoi wrote:

hello @Naveen Boga, thank you for your answer but I’m so sorry I didn’t describe it clearly.

The idea is I want to create a new data view delegate and select the same data with some additional filtering or dynamic calculations. However, I don’t want to create a new view as your answer because it has  a risk that Acumatica will update this command in the future.

So I suppose if we could customize the view delegate by creating graph extension, something like this

public class APVendorPriceMaint_Extension : PXGraphExtension<APVendorPriceMaint>
{

    public IEnumerable records()
    {

        // 1. get records return from base statement (the source code of Acumatica)
        // 2. get value of APVendorPriceFilterExt.usrShippingTermID
        // 3. filter records from step 1 by additional condition from step 2

    }
}

 

But I don’t know how to get the records return from original statement in graph extension

 

@mrthanhkhoi  You can achieve this by using the “PXOverride” attribute on the “records()” data view delegate in the graph extension. You’ll then also want to add a method delegate “Func<IEnumerable> baseImpl” as the first parameter of this override method and invoke that to get the enumerable collection of records that you can then filter further. It’ll look something like this:

public class APVendorPriceMaint_Extension : PXGraphExtension<APVendorPriceMaint>
{
    [PXOverride]
    public virtual IEnumerable records(Func<IEnumerable> baseImpl)
    {

        // 1. get records return from base statement (the source code of Acumatica)
        var recordsCollection = baseImpl?.Invoke();

        // 2. get value of APVendorPriceFilterExt.usrShippingTermID
        // 3. filter records from step 1 by additional condition from step 2


        return recordsCollection; // or return whatever modified collection you have at this point
    }
}

You’ll get the collection of records from the base method, then you can filter them however you like, and then return that collection and the grid on the webpage will display your filtered results.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings