Solved

baseMethod in Action Override Overrode is null

  • 6 June 2023
  • 3 replies
  • 127 views

Userlevel 7
Badge +9

Hello All,

I have done action override a hundred times but I am facing an issue in Close Action of ServiceOrder that I am not sure why is happening. The problem is the "baseMethod" has a null value and as a result, I get an error that "An unhandled exception has occurred in the function 'MoveNext'. Please see the trace log for more details." Without this piece of customization, it is working just fine. Please note I have other stuff so that I am calling Base1 and Base2 in addition to the Base in my graph extension. Here is the part of the code relevant to the issue. Any help is appreciated.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.FS;

namespace Test
{
public class MyServiceOrderEntryExt : PXGraphExtension<ServiceOrderEntryWorkflow, ServiceOrderEntryVisibilityRestriction, ServiceOrderEntry>
{
public static bool IsActive() => true;

[PXOverride]
public delegate IEnumerable CloseOrderDelegate(PXAdapter adapter);
[PXUIField]
[PXButton]
public virtual IEnumerable CloseOrder(PXAdapter adapter, CloseOrderDelegate baseMethod)
{
List<FSServiceOrder> list = adapter.Get<FSServiceOrder>().ToList();
// Do my validations on the list and determine the invalid items and add to invalidList
string invalidList = "List of invalid items";

if (!string.IsNullOrWhiteSpace(invalidList))
{
if (Base.ServiceOrderRecords.View.Ask("Warning ...", invalidList, MessageButtons.YesNo) == WebDialogResult.Yes)
{
return baseMethod?.Invoke(adapter);
}
}

return adapter.Get();
}
}
}

 

icon

Best answer by Naveen Boga 6 June 2023, 04:49

View original

3 replies

Userlevel 7
Badge +17

Hi @aaghaei  I just did minor changes to your code and verified. The below code is working as expected.

Please check from your end.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using PX.Common;
using PX.Data;
using PX.Objects.FS;

namespace Test
{
public class MyServiceOrderEntryExt : PXGraphExtension<ServiceOrderEntryWorkflow, ServiceOrderEntryVisibilityRestriction, ServiceOrderEntry>
{
public static bool IsActive() => true;


public delegate IEnumerable CloseOrderDelegate(PXAdapter adapter);
[PXOverride]
[PXButton]
public IEnumerable CloseOrder(PXAdapter adapter, CloseOrderDelegate baseMethod)
{
// List<FSServiceOrder> list = adapter.Get<FSServiceOrder>().ToList();
// Do my validations on the list and determine the invalid items and add to invalidList
string invalidList = "List of invalid items";

if (!string.IsNullOrWhiteSpace(invalidList))
{
if (Base.ServiceOrderRecords.View.Ask("Warning ...", invalidList, MessageButtons.YesNo) == WebDialogResult.Yes)
{
return baseMethod(adapter);
}
}

return adapter.Get();
}
}
}

 

Userlevel 7
Badge +9

Thanks @Naveen Boga 

That I was meaning to do 😂to override the method not the delegate. 

Userlevel 4
Badge

Thanks for this topic.  Just had the same problem, same cause => was overriding the delegate not the method!

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