Solved

I cant override a Method

  • 10 September 2023
  • 7 replies
  • 260 views

Userlevel 1

my acumatica build: 22.215.0056

this is the original method to override:

public virtual void RefreshRates(RefreshFilter filter, List<RefreshRate> list)

this is the graph extended:

    public class RefreshCurrencyRatesExt : PXGraphExtension<RefreshCurrencyRates>
    {
        public delegate void RefreshRatesDelegate(RefreshFilter filter, List<RefreshRate> list);
        [PXOverride]
        public void RefreshRates(RefreshFilter filter, List<RefreshRate> list, RefreshRatesDelegate baseMethod)

        {
            baseMethod(filter, list);
            throw new Exception("");
        }

    }

here the error message:

Parameter count does not match passed in argument value count.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Parameter count does not match passed in argument value count.

 

any idea?

icon

Best answer by Naveen Boga 11 September 2023, 08:47

View original

7 replies

Userlevel 4
Badge +2

I looked at the class source code you mention briefly and noticed something curious.  There is a partial class defined in the class file for RefreshRate that includes a class header comment referencing:

     “RefreshCurrencyRates.RefreshRates(RefreshFilter, List{RefreshRate}, string)”


Notice the third parameter.  Is this an incorrect header comment, or is there a third parameter hidden from us somehow? I don’t know the answer.
 

In any case, two things I would suggest to try are (1) in your PXOverride method, call Base.RefreshRates() instead of the delegate method.  However, I’m not quite sure if that would cause an endless loop if calling the Base would then call the PXOverride method again.  (2) Don’t PXOverride the method, but instead add an event handler for RefreshFilter_RowSelected that calls your new method instead of the base version of RefreshRates().

Userlevel 1

Thank you very much Tony I will follow your advice.

Userlevel 1

the first option I hope is well implemented but fail:

        [PXOverride]
        public void RefreshRates(RefreshFilter filter, List<RefreshRate> list)
        {
            // Your custom logic here
            Base.RefreshRates(filter, list); // Call the base method directly
            throw new Exception("");
        }

Userlevel 7
Badge +17

@victorcerecero  I have looked into this but something we were not able to figure it out. I don’t see any issues with your code.

As suggested by Tony, it works with the 2nd approach. But in the future version, if they make any changes to this code, again we need to work and add the base code to your method.

 

I would strongly recommend you raise a support case and check with Acumatica on this. 

Userlevel 1

 

You're right Naveen, I had also thought about it. I'm going to do it. Thank you very much, everyone, for your time.

Userlevel 3
Badge +2

Hello @victorcerecero . You may already have found a solution. But just in case, looks like @Tony Lanzer ‘s 2 option works well: Don’t PXOverride the method, but instead add an event handler for RefreshFilter_RowSelected that calls your new method instead of the base version of RefreshRates().

So, for example you can write your custom method and override the RowSelected evet to set your method as the delegate. Here is an example with a custom method with a condition to execute or call the original one:

        protected virtual void _(Events.RowSelected<RefreshFilter> e, PXRowSelected baseMethod)
{
RefreshFilter filter = e.Row;
if (filter != null)
{
Base.CurrencyRateList.SetProcessDelegate(list => CustomRefreshRates(filter, list));
}
}

public virtual void CustomRefreshRates(RefreshFilter filter, List<RefreshRate> list)
{
if (your_condition == true)
{
// Do your custom process here
}
else
{
// Call original method in some other cases
this.Base.RefreshRates(filter, list);
}
}

 

Userlevel 1

Hello @Marco Villasenor, Thank you for your response, Yes, indeed, the issue was resolved through what you mentioned. The event finally allowed adding the required functionality. Thank you very much, Marco. Greetings to our friends at Interastar.

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 — 2024  Acumatica, Inc. All rights reserved