Wednesday, June 3, 2026

SysOperation framework execution mode

Personally, I use the SysOperation Framework (SOF) frequently when I am writing business logic code that requires execution in batch.

The execution mode of your operation can be controlled by the framework in different ways depending on the situation. One important factor is SysOperationExecutionMode. When running operations using SOF, you can control the execution mode to best suit your needs.

For example, if you add a customization to a standard F&O process, you don't want that impact that process by introducing a lengthy operation or even worse, an exception. For those situations, I use the ScheduledBatch or the ReliableAsynchronous modes.

When executing an SOF operation with ScheduledBatch or the ReliableAsynchronous modes, the operation gets added to batch and the execution of the caller continues. The caller does not have to wait for the operation to finish. It seems to be asynchronous but it's actually just running in batch.

Below are the different execution modes of the SysOperation framework.

Synchronous

The default mode. Runs on the same thread as the caller. The caller thread is paused until the operation is completed.

ReliableAsynchronous

Runs in the batch framework and the batch job is automatically deleted regardless of the final status of the batch job.

ScheduledBatch

Runs in the batch framework and the batch job remains visible after execution regardless of the final status of the batch job.

Asynchronous

Runs on a separate thread as the caller. The caller thread is not paused.

Code

Your controller class extends the SysOperationServiceController class and the default execution mode is set in the new method of the base class SysOperationServiceController class.


public void new(IdentifierName _className='',
    IdentifierName _methodName='',
    SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Asynchronous)
{
    super(_executionMode);

    className = _className;
    methodName = _methodName;

    progressWait = SysOperationProgressWait::construct();

    this.parmShowProgressForm(false);
}

You can override the execution mode in the new method of your own controller class.


public void new(IdentifierName _className = '',
    IdentifierName _methodName = '',
    SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Asynchronous)
{
    super(_className, _methodName, _executionMode);
    
    this.parmClassName(classStr(AVSysOpMultiSelectTemplateService));
    this.parmMethodName(methodStr(AVSysOpMultiSelectTemplateService, runQuery));
    //ScheduledBatch: the batch job remains visible after execution.
    //ReliableAsynchronous: the batch job is deleted automatically after execution.
    this.parmExecutionMode(SysOperationExecutionMode::Synchronous);
}

You can set the execution mode in code using the parmExecutionMode property.


public static void main(Args _args)
{
    AVSysOpMultiSelectTemplateController operation = AVSysOpMultiSelectTemplateController::construct();

    //can call initializeFromArgs() if menu item contains execution mode info.
    //operation.initializeFromArgs(_args);
    operation.parmShowDialog(true);
    operation.parmExecutionMode(SysOperationExecutionMode::ScheduledBatch);
    operation.startOperation();
}

Menu item

If your operation is launched using using a menu item, you can control the execution mode with the Enum Type and Enum parameter properties on the menu item.

Note:
If you rely on the menu item to initialize your operation, calling initializeFromArgs of the SysOperationServiceController base class is required.


public static void main(Args _args)
{
    AVSysOpMultiSelectTemplateController operation = AVSysOpMultiSelectTemplateController::construct();
    
    //call initializeFromArgs() to retrieve execution mode, class name and class method.
    operation.initializeFromArgs(_args);
    operation.parmShowDialog(true);
    operation.startOperation();
}

Below is the standard SOF initializeFromArgs method of the SysOperationServiceController class. It retrieves the execution mode from the menu item that launched the operation.


public void initializeFromArgs(Args a)
{
    container serviceInfo = SysOperationServiceController::parseServiceInfo(a);

    this.parmClassName(conPeek(serviceInfo, 1));
    this.parmMethodName(conPeek(serviceInfo, 2));
    if (conLen(serviceInfo) == 3)
    {
        this.parmExecutionMode(conPeek(serviceInfo, 3));
    }
    this.parmArgs(a);
}

No comments:

Post a Comment