Search code examples
customizationacumatica

In Acumatica, why is my JournalEntry extension delegate not firing?


In an Acumatica customization, I want to check journal entries after they are posted to see if they are being posted to a specific branch so I can create entries for another Tenant.

I am using the JournalEntry graph and creating a delegate on the ReleaseBatch method.

I know the extension is being hit because anytime I click anything on the Journal Entry screen, breakpoint on private bool testingExtensionIsActive = true; gets hit. In order to get the code to compile I had to put the ReleaseBatchDelegate baseMethod before the bool unholdBatch = false parameter. Optional parameters have to go at the end of the signature. Normally the baseMethod goes at the end of the signature for the other delegates I have created.

I also tried another delegate just to see if I could get ANYTHING to work. The second delegate in my code is for the PostGraph graph. It has a simple signature so I thought that would rule out the issue I just describe above with the optional paramater.

I cannot hit the breakpoint set on string joe = "joe"; in either delegate.

...

public class JournalEntry_Extension : PXGraphExtension<JournalEntry>
{
    private bool testingExtensionIsActive = true;

    public delegate void ReleaseBatchDelegate(IList<Batch> list, IList<Batch> externalPostList, bool unholdBatch);
    public virtual void ReleaseBatch(IList<Batch> list, IList<Batch> externalPostList, ReleaseBatchDelegate baseMethod,
        bool unholdBatch = false)
    {
        string joe = "joe";

        baseMethod(list, externalPostList, unholdBatch);
    }
}


// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class PostGraph_Extension : PXGraphExtension<PostGraph>
{
    public delegate void PostBatchProcDelegate(Batch b);
    public virtual void PostBatchProc(Batch b, PostBatchProcDelegate baseMethod)
    {
        string joe = "joe";

        baseMethod(b);
    }
}

...

I confirmed I am using the correct graphs/methods as I am able to hit breakpoints in both methods I am trying to override. This is the breakpoint in the ReleaseBatch method of the JournalEntry graph:

enter image description here

This is the breakpoint on the PostGraph method enter image description here

What am I doing wrong? Any help would be greatly appreciated.


Solution

  • You can't override ReleaseBatch as it is a static method. I recommend to review the ReleaseBatchProc(Batch b, bool unholdBatch = false) of the PostGraph class and try to override that one as it is a public virtual method.

    public static void ReleaseBatch(IList<Batch> list)
    {
        ReleaseBatch(list, null);
    }
    
    public static void ReleaseBatch(IList<Batch> list, IList<Batch> externalPostList)
    {
        ReleaseBatch(list, externalPostList, false);
    }
    public static void ReleaseBatch(IList<Batch> list, IList<Batch> externalPostList, bool unholdBatch)
    {
        PostGraph pg = PXGraph.CreateInstance<PostGraph>();
    
        bool doPost = (externalPostList == null);
        Batch batch = null;
        for (int i = 0; i < list.Count; i++)
        {
            pg.Clear(PXClearOption.PreserveData);
    
            batch = list[i];
            pg.ReleaseBatchProc(batch, unholdBatch);
    
            if ((bool)batch.AutoReverse && pg.glsetup.Current.AutoRevOption == "R")
            {
                Batch copy = pg.ReverseBatchProc(batch);
                list.Add(copy);
            }
    
            if (pg.AutoPost)
            {
                if (doPost)
                {
                    pg.PostBatchProc(batch);
                }
                else
                {
                    externalPostList.Add(batch);
                }
            }
        }
    }