Implement the SysOperationSandbox framework

Completed

Finance and operations apps provides several ways for you to run time-consuming operations.

  • You can use batch processes to perform lengthy tasks that are implemented on the batch servers.
  • Occasionally, you'll need to run processes in the web client. If you run the process in synchronous mode, the web browser will be frozen until the process completes. The Application Object Server (AOS) might disconnect the client if the process takes too long, which will eventually fail the process that was running in the web client. To avoid this situation, you can run an asynchronous process, which will leave the web client free for the user.
  • You can use the SysOperationSandbox framework, which will implement the long running process in a separate session in async mode. Additionally, it shows the waiting page for the async process, without having the user interface frozen. It also has a Cancel button to abandon the process.

SysOperationSandbox

By using SysOperationSandbox, you can run a synchronous operation on the asynchronous session that's happening on the web client. The framework will help you run two client sessions in parallel. The first session is an async session that runs the business logic in a static class. The second session communicates with the user interface to keep it live without allowing a timeout. As a result, you can run a synchronous session in a form without the risk of the web client disconnecting.

The sandbox framework creates a new instance of class and runs it in an asynchronous mode. After the class has completed implementation, the synchronous process will continue. The framework can marshal the state of the current instance to the new instance by using the pack()/unpack() method prior to starting the run() method. The same process continues when the new instance is back to the current instance. Hence, the state of the class must be properly serialized in the pack() and unpack() methods, which is already available for classes that are derived from RunBaseBatch.

Example

A custom table called BankCheque has two fields: BankAccount and CheckNo. You need to run a user interface-driven process to add 100 new check numbers, starting from 10000, by using the sandbox framework.

  1. Create a new class with business logic to create 100 new check numbers. Pack and unpack methods are also created in the class.
class SandBoxLabHelper
{
    public static container AsyncInfo(container _parameters)
    {

        str bankAccount = conPeek(_parameters, 1);
        int checkStart = conPeek(_parameters, 2);
        int checkCount = conPeek(_parameters, 3);
        
        BankChequeTable   bankChequeTable;

        for(int i = checkStart; i < (checkStart + checkCount); i++)
        {
            bankChequeTable.clear();
            bankChequeTable.AccountID = bankAccount;
            bankChequeTable.ChequeNum = int2Str(i);
            bankChequeTable.insert();
        }
        return [true];
    }

    public container pack()
    {
        return conNull();
    }

    public boolean unpack(container _packedClass)
    {
        return true;
    }

	}
  1. Create a new form and add a button. Write code in the clicked() method of the button to run the preceding AsyncInfo static method by using the sandbox framework.
public void clicked()
{
   boolean result;
   container mCon;
   mCon = conIns(mCon, 1, "1111111111");
   mCon = conIns(mCon, 2, 100000);
   mCon = conIns(mCon, 3, 100);
            
   [result] = SysOperationSandbox::callStaticMethod(classNum(SandBoxLabHelper), staticMethodStr(SandBoxLabHelper, AsyncInfo), mCon, "Processing", "Completed", "Cancelled");
   super();
}