Solved

Hide specified value in selector field

  • 19 March 2024
  • 6 replies
  • 62 views

I am trying to filter out/hide a location id in the selector for the Inventory Summary screen. 

 

Any ideas on this would be appreciated. Thanks in advance!

icon

Best answer by Leonardo Justiniano 20 March 2024, 04:50

View original

6 replies

Badge +11

Without more information, I’m going to assume you want this Location to behave in an otherwise normal fashion, except for this particular selector. In order to achieve this, this particular selector will need to be customized.

Userlevel 6
Badge +4

Hi @bguzman43 

You have to override the attribute Location and modify the internal selector to accommodate your new filtering criteria. In the following example I am adding value “ExcuideLoc” which will be used to exclude a specific location:

public class LocationExtAttribute : LocationAttribute
{
public LocationExtAttribute(Type SiteIDType, Type ExcludeLoc) : base(SiteIDType)
{
_SiteIDType = SiteIDType ?? throw new PXArgumentException(nameof(SiteIDType), ErrorMessages.ArgumentNullException);

Type search = BqlTemplate.OfCommand<
Search<INLocation.locationID,
Where<INLocation.siteID, Equal<Optional<BqlPlaceholder.A>>,
And<INLocation.locationCD, NotEqual<BqlPlaceholder.B>>>>>
.Replace<BqlPlaceholder.A>(_SiteIDType)
.Replace<BqlPlaceholder.B>(ExcludeLoc)
.ToType();

var attr = new LocationDimensionSelectorAttribute(search, GetSiteIDKeyRelation(SiteIDType));
_Attributes.Add(attr);
_SelAttrIndex = _Attributes.Count - 1;
}
}

Once that is implemented you need to replace the current attribute on the field LocationID with the new attribute:

[PXMergeAttributes(Method = MergeMethod.Replace)]
[LocationExt(typeof(InventorySummaryEnqFilter.siteID), typeof(LocationExtType.b_INV), Visibility = PXUIVisibility.Visible, KeepEntry = false, DescriptionField = typeof(INLocation.descr), DisplayName = "Location")]
protected void _(Events.CacheAttached<InventorySummaryEnqFilter.locationID> e) { }

Note that I am passing typeof(LoccationExtType.b_INV) which is a standard constant I defined.

You can find the full example here:

Removes a Location named "B_INV" from the list of locations based on a selected warehouse (SiteID) (github.com)

 

Inventory Summary Screen 

Before

After

 

Other options

You can write directly the query using PXDimensionSelector attribute, but will change the original idea of having all encapsulated within the Location attribute implementation.

 

Hope this approach helps.

 

 

 

Badge +11

@Leonardo Justiniano - Just out of curiosity, what benefit does this have over appending a PXRestrictor attribute in the CacheAttached event?

Userlevel 6
Badge +4

Hi @darylbowman 

 

I am replacing the previous declaration made by Acumatica with my extended attribute.

InventorySummaryEnqFilter DAC

In doing so, I preserve any implementation Acumatica made within the attribute like events and dependencies.

LocationAttribute

 

I always try to make any customization as closer to Acumatica as possible. 

Badge +11

Understood, but I wasn’t aware that PXRestrictor changes the original selector in any way, except by changing the BQL statement, which your solution is also doing. Am I wrong?

Userlevel 6
Badge +4

Hi @darylbowman 

Yes. You can use PXRestrictor on top of the original attribute to affect the original selector and then inject it through a CacheAttached merge. 

...
using PX.Objects.IN;
...

public class InventorySummaryEnq_Extension : PXGraphExtension<InventorySummaryEnq>
{
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRestrictor(typeof(Where<INLocation.locationCD, NotEqual<LocationExtType.b_INV>>),"")]
protected void _(Events.CacheAttached<InventorySummaryEnqFilter.locationID> e) { }
}

Implementing the Location extension as first described will allow you to encapsulate any business rule you want to verify for specific locations in just one place. That is why I opted for the first approach. However, your point is also right and for a simple filtering a PXRestrictor would work.

 

Thank you!

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