How To Call Non Public Method Of Acumatica
Hello everybody,
today I want to share with you how it's possible to call some methods of Acumatica, which are not public, and which you don't want to copy/paste completely into your source code. In that case reflection will save you. Consider calling of InsertSOAdjustments method of graph SOOrderEntry below.
MethodInfo invokeSOAdjustment = typeof(SOOrderEntry).GetMethod( "InsertSOAdjustments", BindingFlags.Instance | BindingFlags.NonPublic, Type.DefaultBinder, new[] { typeof(SOOrder), typeof(ARPaymentEntry), typeof(ARPayment) }, null); invokeSOAdjustment.Invoke(Base, new object[] { order, docgraph, payment });
Also I want to give you a word of warning, that such approach potentially will not be certified, and another way of usage will be the one below:
In extension of SOOrderEntry create lines like those:
[PXOverride] public void InsertSOAdjustments(SOOrder order, ARPaymentEntry docgraph, ARPayment payment, Action<SOOrder, ARPaymentEntry, ARPayment> baseAction) { baseAction(order, docgraph, payment); }
and then just call InsertSOAdjustments method whenever you'll have a need for this.
Summary
Because Acumatica is written with C# which is very powerful language which gives you a lot of features you can easily achieve a lot of thigs, also be careful with usage of reflection. Somtime even more then Acumatica team anticipated themselves.