Skip to main content
Answer

I cant override a Method

  • September 10, 2023
  • 7 replies
  • 596 views

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?

Best answer by Naveen Boga

@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. 

7 replies

Tony Lanzer
Pro III
Forum|alt.badge.img+2
  • Pro III
  • September 11, 2023

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().


  • Author
  • Freshman I
  • September 11, 2023

Thank you very much Tony I will follow your advice.


  • Author
  • Freshman I
  • September 11, 2023

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("");
        }


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • September 11, 2023

@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. 


  • Author
  • Freshman I
  • September 11, 2023

 

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


Marco Villasenor
Jr Varsity II
Forum|alt.badge.img+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);
}
}

 


  • Author
  • Freshman I
  • February 3, 2024

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.