Skip to main content
Answer

baseMethod in Action Override Overrode is null

  • June 6, 2023
  • 3 replies
  • 247 views

aaghaei
Captain II
Forum|alt.badge.img+10

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

 

Best answer by Naveen Boga

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

 

3 replies

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

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

 


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • June 6, 2023

Thanks @Naveen Boga 

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


Forum|alt.badge.img+1
  • Varsity II
  • August 13, 2023

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