Skip to main content

Hello all,

I have a Delegate which is triggered and also executes the base method from inside the delegate. The problem I have is that the remainder of the code after calling the base method is not executed. Any idea why? Here is the code. The breakpoint on “baseMethod...” gets hit but on “if (...” does not.

public class MyEPApprovalProcessExt : PXGraphExtension<EPApprovalProcess>
{
#region editDetailDelegate
public delegate IEnumerable editDetailDelegate(PXAdapter adapter);
;PXOverride]
]PXEditDetailButton]
public virtual IEnumerable editDetail(PXAdapter adapter, editDetailDelegate baseMethod)
{
baseMethod?.Invoke(adapter);

// Nothing is executed from here forward.
if (Base.Records.Current.RefNoteID.Value != null)
{
// Do some stuff
}

return adapter.Get();
}
#endregion
}

Any help is appreciated

Hi @aaghaei,

If Construction module is enabled, then there is a PXRedirectRequiredException in editDetail. You need to catch it and throw it again after your stuff.

try
{
return baseMethod.Invoke(adapter);
}
catch (PXRedirectRequiredException redirect)
{
if (Base.Records.Current.RefNoteID.Value != null)
{
// Do some stuff
}

throw;
}

 


​Thank you for the reply @Zoltan Febert 

With the changes you suggested, my issue is swapped. Basically, when I double click on a record in Approvals screen, the editDetail method takes me to the document. In my original code, the custom code after the baseMethod was not executed. With the changes you suggested, now my code is executed but I am not directed to the Document before executing my custom code.

Basically, what I am trying to do is to open a new window automatically after I am redirected to the document from the Approvals screen. I am trying to open a custom screen, but I am putting a redirect to ProjectEntry so you don’t receive error if you want to test it. Here is the simplified code if you or someone else kindly can give it a try and help me out.

public class MyEPApprovalProcessExt : PXGraphExtension<EPApprovalProcess>
{
#region editDetailDelegate
public delegate IEnumerable editDetailDelegate(PXAdapter adapter);
rPXOverride]
dPXEditDetailButton]
public virtual IEnumerable editDetail(PXAdapter adapter, editDetailDelegate baseMethod)
{
try
{
return baseMethod.Invoke(adapter);
}
catch (PXRedirectRequiredException redirect)
{
if (Base.Records.Current.RefNoteID.Value != null)
{
ProjectEntry target = PXGraph.CreateInstance<ProjectEntry>();
target.Project.Current = target.Project.Search<PMProject.contractID>(0);
throw new PXPopupRedirectException(target, PX.Objects.PM.Messages.Project, true);
}

throw;
}
}
#endregion
}

 


Hi @aaghaei,

So actually you want to throw two different exceptions from the same function?
There is an AggregateException class in c#, but I am not sure the framework is prepared to handle it.

public class MyEPApprovalProcessExt : PXGraphExtension<EPApprovalProcess>
{
#region editDetailDelegate
public delegate IEnumerable editDetailDelegate(PXAdapter adapter);
[PXOverride]
[PXEditDetailButton]
public virtual IEnumerable editDetail(PXAdapter adapter, editDetailDelegate baseMethod)
{
var exceptions = new List<Exception>();
try
{
return baseMethod.Invoke(adapter);
}
catch (PXRedirectRequiredException redirect)
{
exceptions.Add(redirect);
if (Base.Records.Current.RefNoteID.Value != null)
{
ProjectEntry target = PXGraph.CreateInstance<ProjectEntry>();
target.Project.Current = target.Project.Search<PMProject.contractID>(0);
var popup = new PXPopupRedirectException(target, PX.Objects.PM.Messages.Project, true);
exceptions.Add(popup);

throw new AggregateException(exceptions);
}

throw;
}
}
#endregion
}

 


Thank you @Zoltan Febert 

the code is being executed up to the point of aggregation 

 

but when throws it I receive this errors that “One or more errors occurred.” without any further details.


Hi @aaghaei were you able to find a solution? Thank you!


Hi Chris, thanks for the follow up. No, not really.


Reply