@aaghaei In that case, if you just need access to the parent graph inside TheMethod, then @Zoltan Febert‘s approach should work.
If you want a cleaner approach to this, I suggest using a FlaggedModeScope, which is a disposable class defined in PX.Objects.Common.Scopes. You can define an inherited class of FlaggedModeScopeBase that accepts the JournalEntry as a parameter. Then you can wrap the body of the override of ReleaseDocProc inside a using that creates an instance of the inherited class containing the reference to the JournalEntry object.
Example:
using PX.Objects.Common.Scopes;
public class JournalEntryFlaggedModeScope : FlaggedModeScopeBase<JournalEntryFlaggedModeScope, JournalEntry>
{
public JournalEntryFlaggedModeScope(JournalEntry parameters) : base(parameters) { }
}
public class CDPRDocumentProcessExt : PXGraphExtension<PRReleaseProcess>
{
public static bool IsActive() => true;
public delegate void ReleaseDocProcDelegate(JournalEntry je, PRPayment doc);
[PXOverride]
public virtual void ReleaseDocProc(JournalEntry je, PRPayment doc, ReleaseDocProcDelegate baseMethod)
{
using (new JournalEntryFlaggedModeScope(je))
{
baseMethod?.Invoke(je, doc);
}
}
public delegate void TheMethodDelegate();
[PXOverride]
public virtual void TheMethod(TheMethodDelegate baseMethod)
{
if (JournalEntryFlaggedModeScope.IsActive)
{
var je = JournalEntryFlaggedModeScope.Parameters;
}
baseMethod?.Invoke();
}
}
The benefit of this approach is that the life-cycle of the FlaggedModeScope object can be handled by the using block. Then, in your override of TheMethod, you can check whether the scope is active and then perform your custom functionality there. You don’t have to check whether or not the JournalEntry reference exists, because if the scope is active, then the parameter will supply the JournalEntry object. If the scope is not active, because TheMethod is being used by another part of the application, then the custom logic is ignored and you don’t have to worry about breaking existing functionality.