Question

Filter grid records by custom field

  • 28 April 2024
  • 3 replies
  • 36 views

Userlevel 3
Badge

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;

 


3 replies

Userlevel 7
Badge +17

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

 

Userlevel 3
Badge

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

Userlevel 2
Badge +1

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved