Custom Code on AP Invoice Release

Hi Everyone,

What to share example with you how to call custom code during AP invoice release. In general process for AP is very similar to what is described in Acumatica T300 Customization Guide in Lesson 7: Customizing the Logic of the Release Action.

Here you also need to find the best place where you can put your custom code and than write it there. Similar to guide above the best place is actually persisting method of APReleaseProcess graph.
Lets check check how to investigate code first and when write a logic.

Preparation
From APInvoiceEntry graph you can find the method that release the invoice. Relese method is easy to find from Name.

If you drill down in the method that is called form PXLongOperation you will be navigated to APDocumentRelease. APDocumentRelease is mass processing graph where you can release multiple AP documents in the user interface.

From there you can drill down to ARReleaseProcess that is actually main graph for release operation.
There you can see save action that commits everything in the database.

Save button will call Persist Method that is also quite special as it does not call base graph Persist. In that case graph logic for committing changes to database have to be triggered manually. Exactly this you can see in the Persist method of  ARReleaseProcess.

Customization
When we have found the place where to do customization we can start development.

First thing is to create extension for ARReleaseProcess graph and override Persist method:

public class APReleaseProcess_Extension : PXGraphExtension<APReleaseProcess>
{
    public delegate void PersistDelegate();
    [PXOverride]
    public void Persist(PersistDelegate baseMethod)
    { baseMethod(); }
}

We also need to define PXSelect for every custom table we want to save. This is required to initialize cache and add it to named views collection.

public PXSelect<AACustomTable> ViewForCustomTable;

In the Persist method we can embed our logic after base code saves the record.

AACustomTable row = ViewForCustomTable.Insert();
row.TableValue = DateTime.Now.ToString();

ViewForCustomTable.Update(row);

When we ready to save data, we can trigger it with Cache.Persist(…);

ViewForCustomTable.Cache.Persist(PXDBOperation.Insert);
ViewForCustomTable.Cache.Persist(PXDBOperation.Update);

Final RowPersisted notification can be also triggered with our code:

ViewForCustomTable.Cache.Persisted(false);

That is actually it. Please see whole code below.

Have a nice development!

Leave a Reply

Please rate*

Your email address will not be published. Required fields are marked *