I’ve found bits of code that show ways to capture the process of creating matrix items from the Create Matrix Items screen (IN203500), but nothing from the Template Items screen.
I’ve tried overriding the TemplateInventoryItemMaint’s CreateMatrixItemsHelper and it does get called when it is being instantiated but my override of CreateUpdateMatrixItems is not being called.
namespace MyMods
{
public class TemplateInventoryItemMaint_Extension : PXGraphExtension<PX.Objects.IN.Matrix.Graphs.TemplateInventoryItemMaint>
{
public delegate CreateMatrixItemsHelper GetCreateMatrixItemsHelperDelegate();
[PXOverride]
public virtual CreateMatrixItemsHelper GetCreateMatrixItemsHelper(
GetCreateMatrixItemsHelperDelegate baseMethod)
{
var baseHelper = baseMethod();
return new MyCreateMatrixItemsHelper(Base);
}
public class MyCreateMatrixItemsHelper : CreateMatrixItemsHelper
{
public MyCreateMatrixItemsHelper(PXGraph graph) : base(graph) { }
public override void CreateUpdateMatrixItems(InventoryItemMaintBase graph, InventoryItem templateItem, IEnumerable<MatrixInventoryItem> itemsToCreateUpdate,
bool create, Action<MatrixInventoryItem, InventoryItem> beforeSave = null)
{
base.CreateUpdateMatrixItems(graph, templateItem, itemsToCreateUpdate, create, beforeSave);
}
}
}
}
The call that I want to intercept, CreateUpdateMatrixItems, is being called in CreateMatrixItemsExt.cs (within the CreateUpdate method).
The CreateUpdate action that is called looks like this:
PXLongOperation.StartOperation(base.Base, delegate
{
TGraph val = PXGraph.CreateInstance<TGraph>();
CreateMatrixItemsExt<TGraph, TMainItem> createMatrixItemsExt = val.FindImplementation<CreateMatrixItemsExt<TGraph, TMainItem>>();
InventoryItemMaintBase inventoryItemMaintBase = ((templateItem.StkItem == true) ? ((InventoryItemMaintBase)PXGraph.CreateInstance<InventoryItemMaint>()) : ((InventoryItemMaintBase)PXGraph.CreateInstance<NonStockItemMaint>()));
inventoryItemMaintBase.DefaultSiteFromItemClass = false;
CreateMatrixItemsHelper helper = createMatrixItemsExt.GetHelper(inventoryItemMaintBase);
AttributeGroupHelper attributeGroupHelper = createMatrixItemsExt.GetAttributeGroupHelper(inventoryItemMaintBase);
helper.CreateUpdateMatrixItems(inventoryItemMaintBase, templateItem, itemsToCreate, create: true, delegate(MatrixInventoryItem t, InventoryItem item)
{
attributeGroupHelper.OnNewItem(templateItem, item, t.AttributeIDs, t.AttributeValues);
});
if (!isImportOrApi)
{
PXLongOperation.SetCustomInfo(new EndCreateUpdateOperationCustomInfo(templateItem.InventoryID, columnAttributeID, rowAttributeID, additionalAttributes));
}
});
The helper.CreateUpdateMatrixItems method, above, doesn’t trigger my code.
Am I coming at this from the wrong angle? There’s not much out there with regards to injecting business logic when creating Matrix items.