Skip to main content
Solved

Override Private Method

  • February 15, 2021
  • 4 replies
  • 669 views

Forum|alt.badge.img

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.

Best answer by Hughes Beausejour

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

 

4 replies

Hughes Beausejour
Acumatica Employee
Forum|alt.badge.img+2
  • Acumatica Developer Support Team
  • Answer
  • February 15, 2021

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

 


Forum|alt.badge.img
  • Author
  • Varsity II
  • February 15, 2021

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 !


Hughes Beausejour
Acumatica Employee
Forum|alt.badge.img+2
  • Acumatica Developer Support Team
  • February 15, 2021

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


Forum|alt.badge.img
  • Author
  • Varsity II
  • February 15, 2021

I see, Thanks for the info!