Solved

Override Private Method

  • 15 February 2021
  • 4 replies
  • 35 views

Hello all,

Is it possible to override a private method of a graph? There have been several times where I have would have liked to, but I lack the rights to such methods from extensions since they are technically different objects as the base graph. Does anyone have a work around for this?

It’s frustrating seeing the exact line of code I need to change to do a simple customization but lacking access to it to make the change. Instead I end up writing an inefficient workaround using event handlers.

Edit: For example, right now I’d like to override OpportunityMaint.FillDefaultBAccountID(), but I can’t using the standard PXOverride attribute & delegate since it’s private.

icon

Best answer by Hughes Beausejour 15 February 2021, 16:45

The workaround is to find all public methods (actions/event handlers) that calls the private method and override them instead of the private method. The worst case scenarios requires to replace the graph with a custom one.

 

For OpportunityMaint.FillDefaultBAccountID there are two public event handlers to override:

  • CROpportunity_RowInserted 
  • CROpportunity_RowUpdated

 

View original

4 replies

Userlevel 3

The workaround is to find all public methods (actions/event handlers) that calls the private method and override them instead of the private method. The worst case scenarios requires to replace the graph with a custom one.

 

For OpportunityMaint.FillDefaultBAccountID there are two public event handlers to override:

  • CROpportunity_RowInserted 
  • CROpportunity_RowUpdated

 

Dang, that’s what I’ve been doing so far. I was hoping there was a better solution I didn’t know about. Anyway, thanks for the quick response @Hughes Beausejour !

Userlevel 3

Technically it is possible to use C# Reflection mechanisms to manipulate private types:
https://asiablog.acumatica.com/2017/02/override-static-method.html

But for most scenarios it is preferable to override only the public types:

https://stackoverflow.com/a/39757549/7376238

I see, Thanks for the info!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2020  Acumatica, Inc. All rights reserved