Reputation: 280
I have added code that I would believe should remove an event handler of an acumatica base class.
public override void Initialize()
{
// Remove the event handler on the APTran object for APTran_SubID_FieldDefaulting so we can override it in this module
Base.FieldDefaulting.RemoveHandler<APTran.subID>(A PTran_SubID_FieldDefaulting);
}
Yet, it still runs through the base code. If I remove this code and keep my new event handler, it runs through the event handler I have and then also appears to run through the Base event handler.
Any suggestions on how to remove the base event handler so it will just use the new event handler?
Upvotes: 1
Views: 1177
Reputation: 280
Solution
Turns out (thanks go to Ivan)
that I do not need to remove the event handler, I just need to declare the event handler in the extension with a third parameter that points back to the original event handler, then I can choose to not call that delegate if that is what I need in my project.
example:
protected void APTran_SubID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e, PXFieldDefaulting del)
{
APTran row = (APTran)e.Row;
if (row == null) { return; }
// do my code here
// skip calling the original event
//del.Invoke(sender, e); -- invokes the Base FieldDefaulting event handler
}
Upvotes: 5