Skip to main content
Question

How to Restrict to copy data from Template Item to generated Matrix items

  • July 7, 2021
  • 0 replies
  • 63 views

praveenpo
Semi-Pro III
Forum|alt.badge.img+3

Hi,
i have few custom fields in InventoryItem DAC and using those fields in both template and stock item screen.When matrix items are generated data is copied to those fields from Template to generated items. I wanted to restrict copying of the data,i have found one method to restrict copying,inherited the class and tried to overrided the method and have my fields included there but inherited class is not at all executing.

Below is the code that i have tried.

 public class CreateMatrixItemsHelperExt : PX.Objects.IN.Matrix.Utility.CreateMatrixItemsHelper
    {
        public CreateMatrixItemsHelperExt(PXGraph graph) : base(graph)
        {
            _graph = graph;
        }

        public delegate void CreateUpdateMatrixItemsDelegate(InventoryItemMaintBase graph, InventoryItem templateItem, IEnumerable<MatrixInventoryItem> itemsToCreateUpdate, bool create,
        Action<MatrixInventoryItem, InventoryItem> beforeSave = null);
        [PXOverride]
        public void CreateUpdateMatrixItems(InventoryItemMaintBase graph, InventoryItem templateItem, IEnumerable<MatrixInventoryItem> itemsToCreateUpdate, bool create,
            CreateUpdateMatrixItemsDelegate baseevenet, Action<MatrixInventoryItem, InventoryItem> beforeSave = null)
        {
            base.CreateUpdateMatrixItems(graph, templateItem, itemsToCreateUpdate, create);

        }

        public delegate InventoryItem AssignRestInventoryFieldsDelegate<TField>(InventoryItemMaintBase graph, InventoryItem item, InventoryItem templateItem);
        [PXOverride]
        public InventoryItem AssignRestInventoryFieldsield<TField>(InventoryItemMaintBase graph, InventoryItem item, InventoryItem templateItem, AssignRestInventoryFieldsDelegate<TField> baseMethod)
        {
            var copy = (InventoryItem)graph.Item.Cache.CreateCopy(item);
            graph.Item.Cache.RestoreCopy(copy, templateItem);

            var excludeFields = new Type[]
            {
                typeof(InventoryItem.inventoryID),
                typeof(InventoryItem.inventoryCD),
                typeof(InventoryItem.descr),
                typeof(InventoryItem.preferredVendorID),
                typeof(InventoryItem.preferredVendorLocationID),
                typeof(InventoryItem.templateItemID),
                typeof(InventoryItem.isTemplate),
                typeof(InventoryItem.Tstamp),
                typeof(InventoryItem.createdByID),
                typeof(InventoryItem.createdByScreenID),
                typeof(InventoryItem.createdDateTime),
                typeof(InventoryItem.lastModifiedByID),
                typeof(InventoryItem.lastModifiedByScreenID),
                typeof(InventoryItem.lastModifiedDateTime),
                typeof(InventoryItem.noteID),
                typeof(InventoryItem.noteID),
                typeof(KNCBInventoryItemExt.usrKNULBrands),
                typeof(KNCBInventoryItemExt.usrKNULMfgs),
            };

            foreach (Type excludeField in excludeFields)
            {
                graph.Item.Cache.SetValue(copy, excludeField.Name,
                    graph.Item.Cache.GetValue(item, excludeField.Name));
            }
            return graph.Item.Update(copy);
        }
    }


Thanks,