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!
Best answer by Leonardo Justiniano
View originalI 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!
Best answer by Leonardo Justiniano
View originalWithout 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.
Hi
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:
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.
Hi
I am replacing the previous declaration made by Acumatica with my extended attribute.
In doing so, I preserve any implementation Acumatica made within the attribute like events and dependencies.
I always try to make any customization as closer to Acumatica as possible.
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?
Hi
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!
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.