-->

Filter Inventory by cross reference

2019-03-06 11:23发布

问题:

I want to customize the filtering of inventory by cross reference along with other properties.

I have added two other cross reference items for a stock item like this.

And now I want to customize, inventory filter in any other forms by the Alternate Type's Alternate Id value.

Thank you!

回答1:

There is no simple way to add search capabilities over Stock Item's Alternate IDs without a customization. Also, keep in mind that we are talking here about the one-to-many relationship between Stock Item and Alternate IDs, which makes it impossible to simply drop Alternate ID column into the Inventory ID selector as this will result in same Stock Item shown multiple times because of a necessary join with the Cross-Reference DAC.

The first thing you need to do is create a database-bound field for the InventoryItem DAC (make sure you create UsrAlternateIDs column in the InventoryItem database) table to concatenate all Alternate IDs of a Stock Item (notice Visibility set to PXUIVisibility.SelectorVisible on PXUIField - this is required to show Alternate IDs column inside the Inventory ID selector):

public class InventoryItemExt : PXCacheExtension<InventoryItem>
{
    public abstract class usrAlternateIDs : IBqlField { }
    [PXDBString(4000, IsUnicode = true)]
    [PXUIField(DisplayName = "Alternate IDs", Visibility = PXUIVisibility.SelectorVisible)]
    public string UsrAlternateIDs { get; set; }
}

Next step is to override the Persist method in the InventoryItemMaint BLC extension to regenerate concatenated Alternate IDs every time the user makes changes in the Cross-Reference tab :

public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
{
    [PXOverride]
    public void Persist(Action del)
    {
        using (PXTransactionScope ts = new PXTransactionScope())
        {
            InventoryItem item = Base.Item.Current;
            if (item != null && Base.itemxrefrecords.Cache.IsDirty)
            {
                string alternateIDs = string.Empty;
                foreach (INItemXRef crossRef in Base.itemxrefrecords.Select())
                {
                    alternateIDs = string.IsNullOrEmpty(alternateIDs) ?
                        crossRef.AlternateID : alternateIDs + "; " + crossRef.AlternateID;
                }
                item.GetExtension<InventoryItemExt>().UsrAlternateIDs = alternateIDs;
                Base.Item.Update(item);
            }

            del();
            ts.Complete();
        }
    }
}

And finally, you should add UsrAlternateIDs in PXSelector FastFilterFields property:

Once these 3 steps are completed, the final result should look as follows:

To concatenate all currently existing Stock Item Alternative IDs in one step, you can implement a custom action on the Stock Items screen. You can remove the action after that.

public class InventoryItemMaint_Extension : PXGraphExtension<InventoryItemMaint>
{
    ...

    public PXAction<InventoryItem> RecalcAlternateIDs;
    [PXButton]
    [PXUIField(DisplayName = "Concatenate Alternate IDs")]
    protected void recalcAlternateIDs()
    {
        PXLongOperation.StartOperation(Base, () =>
        {
            InventoryItemMaint itemMaint = PXGraph.CreateInstance<InventoryItemMaint>();
            var items = PXSelect<InventoryItem, Where<InventoryItem.stkItem, Equal<boolTrue>>>.Select(itemMaint);
            foreach (InventoryItem item in items)
            {
                itemMaint.Clear();
                itemMaint.Item.Current = item;
                itemMaint.itemxrefrecords.Cache.IsDirty = true;
                itemMaint.Actions.PressSave();
            }
        });
    }
}


标签: acumatica