Here is my solution. I’d like to be able to have the option to check items and use an action to process the selected items, but for now, they can select an item and it will move it to the Excluded Items grid.
This is my code in case anyone wants to look at it:
DAC extension
using PX.Data;
namespace SCGC
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public sealed class SCGCInventoryItemExt : PXCacheExtension<PX.Objects.IN.InventoryItem>
{
#region UsrExclude
[PXBool]
[PXUIField(DisplayName = "Exclude", Enabled = true)]
public bool? UsrExclude { get; set; }
public abstract class usrExclude : PX.Data.BQL.BqlBool.Field<usrExclude> { }
#endregion
}
}
Graph Extension:
public class PIGenerator_Extension : PXGraphExtension<PX.Objects.IN.PIGenerator>
{
public override void Initialize()
{
base.Initialize();
Base.InventoryItemsToLock.AllowUpdate = true;
Base.LocationsToLock.AllowUpdate = true;
}
#region Actions
public PXAction<INLocation> ClearExcludedLocations;
[PXUIField(DisplayName = "Clear Excluded Locations", Enabled = true)]
[PXButton(CommitChanges = true)]
public void clearExcludedLocations()
{
WebDialogResult result = Base.ExcludedLocations.Ask(ActionsMessages.Warning, ICSMessages.ClearExcludedLocations,
MessageButtons.OKCancel, MessageIcon.Warning, true);
if (result != WebDialogResult.OK) return;
foreach (var item in this.Base.ExcludedLocations.Select())
{
Base.ExcludedLocations.Delete(item);
}
Base.Actions.PressSave();
}
public PXAction<InventoryItem> ClearExcludedItems;
[PXUIField(DisplayName = "Clear Excluded Items", Enabled = true)]
[PXButton(CommitChanges = true)]
public void clearExcludedItems()
{
WebDialogResult result = Base.ExcludedInventoryItems.Ask(ActionsMessages.Warning, ICSMessages.ClearExcludedItems,
MessageButtons.OKCancel, MessageIcon.Warning, true);
if (result != WebDialogResult.OK) return;
foreach (var item in this.Base.ExcludedInventoryItems.Select())
{
Base.ExcludedInventoryItems.Delete(item);
}
Base.Actions.PressSave();
}
#endregion
#region Event Handlers
protected virtual void INLocation_UsrExclude_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (INLocation)e.Row;
if (row != null)
{
if (row.LocationID != null)
{
ExcludedLocation item = new ExcludedLocation();
item.LocationID = row.LocationID;
Base.ExcludedLocations.Update(item);
cache.Remove(row);
Base.ExcludedLocations.View.RequestRefresh();
}
}
}
protected virtual void InventoryItem_UsrExclude_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
var row = (InventoryItem)e.Row;
if (row != null)
{
if (row.InventoryID != null)
{
ExcludedInventoryItem item = new ExcludedInventoryItem();
item.InventoryID = row.InventoryID;
Base.ExcludedInventoryItems.Update(item);
cache.Remove(row);
Base.InventoryItemsToLock.View.RequestRefresh();
}
}
}
protected virtual void INLocation_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (INLocation)e.Row;
PXUIFieldAttribute.SetEnabled<SCGCINLocationExt.usrExclude>(cache, null, true);
PXUIFieldAttribute.SetEnabled<INLocation.locationCD>(cache, null, false);
PXUIFieldAttribute.SetEnabled<INLocation.descr>(cache, null, false);
}
protected virtual void InventoryItem_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (InventoryItem)e.Row;
PXUIFieldAttribute.SetEnabled<SCGCInventoryItemExt.usrExclude>(cache, null, true);
PXUIFieldAttribute.SetEnabled<InventoryItem.inventoryCD>(cache, null, false);
PXUIFieldAttribute.SetEnabled<InventoryItem.descr>(cache, null, false);
}