Skip to main content
Solved

Hide specified value in selector field


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

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.

 

 

 

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

6 replies

darylbowman
Captain II
Forum|alt.badge.img+13

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.


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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.

 

 

 


darylbowman
Captain II
Forum|alt.badge.img+13

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


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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. 


darylbowman
Captain II
Forum|alt.badge.img+13

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?


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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


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