Hello all,
I am trying to override two methods “ClearRelatedApproval” and “RowUpdated” as shown below and my intention is to prevent original methods from being executed.
public class HCLEPApprovalAutomation<SourceAssign, Approved, Rejected, Hold, Released, SetupApproval> : EPApprovalAutomation<SourceAssign, Approved, Rejected, Hold, SetupApproval>
where SourceAssign : class, IApprovable, IAssign, IBqlTable, new()
where Approved : class, IBqlField
where Rejected : class, IBqlField
where Hold : class, IBqlField
where Released : class, IBqlField
where SetupApproval : class, IAssignedMap, IBqlTable, new()
{
public HCLEPApprovalAutomation(PXGraph graph, Delegate @delegate) : base(graph, @delegate) { }
public HCLEPApprovalAutomation(PXGraph graph) : base(graph) { }
public static bool IsActive() => true;
[PXOverride] //shouldn't be needed really
public override void ClearRelatedApprovals(SourceAssign doc)
{
// Do my stuff
}
[PXOverride] // Shouldn't be needed really
protected override void RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
{
// Do my stuff
}
}Then I call the custom class in APInvoiceEntry graph extension to override the “Approval” as follow:
public class HCLAPInvoiceEntryApprovalWorkflow : PXGraphExtension<APInvoiceEntry_ApprovalWorkflow, APInvoiceEntry_Workflow, APInvoiceEntry>
{
public static bool IsActive() => true;
[PXCopyPasteHiddenView]
[PXViewName(EPMessages.Approval)]
public HCLEPApprovalAutomation<APInvoice, APInvoice.approved, APInvoice.rejected, APInvoice.hold, APInvoice.released, APSetupApproval> Approval;
}
When I try the above, my code is executed without any error but still the original methods also executed. So I tried removing the “RowUpdated” event handler delegate that executes the other method in the base class. This is what I did.
protected override void Init(PXGraph graph)
{
base.Init(graph);
// Remove Class Event Handler
graph.RowUpdated.RemoveHandler<SourceAssign>(base.RowUpdated);
// Remove Approval View Event Handler
PXRowUpdated rowUpdated = (PXRowUpdated)Delegate.CreateDelegate(typeof(PXRowUpdated), approvalObject, graph.GetType().GetField("Approval").GetValue(graph).GetType().GetMethod("RowUpdated", BindingFlags.Instance | BindingFlags.NonPublic));
graph.RowUpdated.RemoveHandler<SourceAssign>(rowUpdated);
}
The above code also is executed without any error but still these two original methods are executed too. Not sure what I am missing.