'Acumatica Customization - How to remove anonymous delegate from PXGraph.RowInsertingEvents Collection?
I‘m working on customization that involves adding extra Sales Person transactions when Cancelling/Correcting an Invoice. As part of the development effort, I have identified that the common method that’s called by both the processes – Cancel Invoice and Correct Invoice, is ReverseDocumentAndApplyToReversalIfNeeded
in the Graph PX.Objects.AR.ARInvoiceEntry
.
I have the custom code to add new salespersons to the ARInvoiceEntry.salesPerTrans
view but when I do after ReverseDocumentAndApplyToReversalIfNeeded
runs, I see that my code doesn’t insert the new records to the view and doesn’t give any error. After much troubleshooting, I’ve found out that there’s a line of code in the method ReverseInvoiceProc
of ARInvoiceEntry.cs that stops from inserting a new row. Here’s that line of code:
this.RowInserting.AddHandler<ARSalesPerTran>((sender, e) => { e.Cancel = true; });
It’s an anonymous delegate that’s added.
I would like to know how can I get hold of this anonymous handler in my custom code so that I can:
- Remove that anonymous handler
- Do my custom logic of adding new rows
- Add the anonymous delegate back to the
RowInsertingEvents
list
I tried to look in the Acumatica code repository but couldn’t find anything that would help me remove anonymous delegate. What I can find was the removal of named handlers, like the below example:
APPaymentEntry pe = CreateInstance<APPaymentEntry>();
pe.RowSelecting.RemoveHandler<APPayment>(pe.APPayment_RowSelecting);
So please let me know how can I dynamically remove that anonymous handler from within my custom code. I have reference to the ARInvoiceEntry graph through the Base property of my extension graph. If you can redirect me to a specific page in the Acumatica Code repository, that would work as well.
Solution 1:[1]
I do not think you could remove this anonymous method from there in a easy way.
However, one approach you could implement is to override the "ReverseDocumentAndApplyToReversalIfNeeded" method and call base method there.
After this you could create a new instance of the ARinvoiceEntry graph (in that same override after calling base method), select the primary record(header) and then try to make your second insert ( this way to avoid the ReverseInvoiceProc.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | cbetabeta |