How to track changes to any kind of Entity in Acumatica

Hello everybody,

today I want to share with you one very cool technique. 

Imagine following scenario: you need to track changes to some entity in Acumatica, and each time that entity changes, execute some kind of logic.

For example each time, when inventory item ( a.k.a. ) stock/non stock item, execute some kind of business logic ( for example send API request call ) to some 3-rd party service. 

You can extend all Acumatica graphs which deal with that entity via overriding Persist method for those graphs.

But how to deal with graphs, written by not Acumatica people, but 3-rd party vendors? How to execute some code for those kinds of events? Code snippet below shows how to achieve this:

public class BusinessEvents : PXGraphExtension<PXGraph>
{
    [PXOverride]
    public void Persist(Action del)
    {
        var exists= Base.Caches[nameof(PX.Objects.IN.InventoryItem)];
        if (exists != null)
        {
            if (exists.IsDirty)
            {
                //Do some kind of logic, related to your needs
                //For example send api refresh call
            }
        }
 
        del();
    }
}

Few explanations for this code. 

1. PXGraphExtension<PXGraph> gives you a way of apply some logic to all graphs

2. As a result, Persist will be executed for persists for entire system. That piece of code should be as efficient as possible

But overall, if you need to track changes to to any of the entities and stay in sync, use that suggestion.

Add comment

Loading