Reputation: 328
I would like to customize the SOLine InventoryID
selector to filter out certain inventory items based on the value of the class they are part of. I've read about the [PXRestrictor]
attribute and how it can be used to filter selectors. This seems like it would work, except that the Item Class name is not available in that DAC, so I tried this:
[PXRestrictor(typeof(SelectFrom<InventoryItem>.
InnerJoin<INItemClass>.On<INItemClass.itemClassID.IsEqual<InventoryItem.itemClassID>>.
Where<INItemClass.itemClassCD.IsEqual<itemClassValue>>), "Custom items")]
but this is apparently not allowed.
It seems like I would need to override the selector itself, but the existing selector is rather convoluted and hidden beneath layers of attributes and I am not sure how to replicate even that, not to mention that option seeming rather near-sighted.
How could I go about this, or is this simply not a good option?
Upvotes: 0
Views: 279
Reputation: 1941
PXRestrictor is used with a where clause to specify how to restrict.
[PXRestrictor(typeof(
Where<Current<InventoryItem.itemClassID>, Equal<itemClassValue>>
), "Custom Items")]
In the example above, itemClassValue must be a type of the classID.
You can Merge with current attributes on the field where the selector is defined as a DAC extension if it needs to exist everywhere or with CacheAttached if only within a specific graph.
Update
As you indicated that you need to allow an entire tree of item classes in the comments, you might try this approach which worked for me in a case where I needed to only allow certain values on a condition.
Add a PXInt field onto SOLine for your BASE item class. Use the RowSelecting event to set it, and then use it in your restrictor.
Sample Base Item Class ID field:
#region BaseItemClassID
[PXInt]
public virtual int? BaseItemClassID { get; set; }
public abstract class baseItemClassID : PX.Data.BQL.BqlInt.Field<baseItemClassID> { }
#endregion
Restrictor to use in CacheAttached to limit to only items of your base item class:
[PXRestrictor(typeof(Where<InventoryItem.baseItemClassID, Equal<myBaseItemClassType>>), "")]
If this is applied to all SOLine records, you will need to add your "when to allow only my specific item class tree" to the restrictor. Remember that the restrictor must return True to give results, so it might need to be "Where NOT my condition OR BaseItemClassID == myBaseItemClassID".
In my case, I needed a simple condition to allow using standard locations where I have some locations configured as special use for segregating certain inventory. I just set a PXBool field to true when I want to allow use of standard locations, and the restrictor flips the allowed selection. I think this concept might work in your case as well as outlined above.
Upvotes: 2