Hello all,
I have a need to override “OnPersisted” method (actually I don’t to be called at all) in a drived class from EPApprovalList (a few level of inheritences) but no matter what I do it still gets called. First I tried to override the method itself. The override method in my custom class gets hit when I trace. In my override I just have one command which is “return” but still the code in the base class somehow gets executed (I am guessing because it is in fact an event handler so the base code is already executed when gets to the override). So I decided the remove the handler when class is initialized. I took two approaches to remove the handler. the codes seems to be executed successfuly as when I trace I do not receive any error and it seems to dp what I want but again I am not sure why still “OnPersisted” methods gets executed. Long story short how I can prevent this method from being executed. Here is the related portion of the drived class I have.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using HCL.Common;
using PX.Common;
using PX.Data;
using PX.Data.BQL.Fluent;
using PX.Data.EP;
using PX.Objects.CS;
using PX.Objects.EP;
using PX.SM;
namespace HCL.ApprovalWorkflow
{
#region EPApprovalAutomation Class
public class HCLEPApprovalAutomation<SourceAssign, Approved, Rejected, Hold, SetupApproval> : EPApprovalAutomation<SourceAssign, Approved, Rejected, Hold, SetupApproval>
where SourceAssign : class, IAssign, IBqlTable, new()
where Approved : class, IBqlField
where Rejected : class, IBqlField
where Hold : class, IBqlField
where SetupApproval : class, IBqlTable, new()
{
public HCLEPApprovalAutomation(PXGraph graph, Delegate @delegate) : base(graph, @delegate) { }
public HCLEPApprovalAutomation(PXGraph graph) : base(graph) { }
public static bool IsActive() => true;
#region Ctor
[PXOverride]
protected override void Init(PXGraph graph)
{
base.Init(graph);
RemovedHandler(graph);
}
private void RemovedHandler(PXGraph graph)
{
dynamic docGraph = graph;
dynamic approval = docGraph.Approval;
MethodInfo mi;
Type type = approval.GetType();
mi = type.GetMethod("OnPersisted", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
docGraph.RowPersisted.RemoveHandler(typeof(SourceAssign), (PXRowPersisted)mi.CreateDelegate(typeof(PXRowPersisted), approval));
// I tried this too but did not work either.
//graph.RowPersisted.RemoveHandler<SourceAssign>(OnPersisted);
}
#endregion
#region OnPersisted
// I tried to override the OnPersisted first so it never is triggered in the base class but not sure why it is triggering. This method gets hit when I trace.
//[PXOverride]
//protected override void OnPersisted(PXCache cache, PXRowPersistedEventArgs e)
//{
// return;
//}
#endregion
}
}