How to handle time consuming operations in Acumatica from code

Hello everybody,

today I want to make a short note on how to handle cases if you need to execute some kind of long operation in Acumatica. Once I had a task, create code that executes some kind of web requests that take some amount of time. When I used simple button, that approach died because of time out. In order to handle it I've decided to use PXLongOperation.StartOperation.

Below goes full sample of code:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public PXAction<SOOrder> Test;
 
    [PXProcessButton(Tooltip = "Test")]
    [PXUIField(DisplayName = "Test")]
    public virtual IEnumerable test(PXAdapter adapter)
    {
        PXLongOperation.StartOperation(thisdelegate
        {
            SomeLongRunningMethod();
        });
        return adapter.Get();
    }
 
    private static void SomeLongRunningMethod()
    {
        // here is some code
    }
}

with such approach you can get better look and feel for your end customers as well as avoid crashing of your app

No Comments

Add a Comment