Skip to main content
Question

Trying to capture CreateUpdate event from CreateMatrixItemsImpl from Template Items (IN203000)

  • September 19, 2025
  • 1 reply
  • 18 views

Forum|alt.badge.img+7

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.

1 reply

Forum|alt.badge.img+2

Hello, ​@Django 
You’re not wrong about needing to intercept CreateUpdateMatrixItems, but you need to inject your custom helper through the CreateMatrixItemsExt<,> extension rather than directly on TemplateInventoryItemMaint.

public class CreateMatrixItemsExt_TemplateItemMaintExt 
: PXGraphExtension<CreateMatrixItemsExt<TemplateInventoryItemMaint, InventoryItem>>
{
public delegate CreateMatrixItemsHelper GetHelperDelegate(InventoryItemMaintBase maint);

[PXOverride]
public virtual CreateMatrixItemsHelper GetHelper(InventoryItemMaintBase maint, GetHelperDelegate baseMethod)
{
var baseHelper = baseMethod(maint);
return new MyCreateMatrixItemsHelper(maint);
}

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)
{
// custom logic before base
PXTrace.WriteInformation("Custom logic before matrix item creation.");

base.CreateUpdateMatrixItems(graph, templateItem, itemsToCreateUpdate, create, beforeSave);

// custom logic after base
PXTrace.WriteInformation("Custom logic after matrix item creation.");
}
}
}



I hope it helps.