Skip to main content

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

 

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

 


Thanks @Naveen Boga 

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


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


Reply