Video blog: Sys Operation framework batch job with parameter X++

Sys Operation Framework: The Sys Operation framework in Microsoft Dynamics AX and D365 Finance and Operations enables efficient batch processing and automation of tasks. Sys Operation framework supports synchronous and asynchronous operations, integrates business logic via service classes, provides user input dialogs, and allows background batch jobs with robust error handling. Sys Operation framework is essential for automating complex tasks and enhancing system performance.

Scenario for Sys Operation Framework:

The user wants to activate customers in bulk by selecting a customer group and expects to run the batch using specific timings.


⦁ High level resolution steps
⦁ Create Contract Class
⦁ Create Service Class
⦁ Create Controller Class
⦁ Create Action Menu Item

Detailed resolution steps

Steps 1: Create Contract Class

The contract class holds all the data that needs to be passed directly to the process. To create this in D365, start by creating a new class with the [DataContractAttribute] attribute at the top. According to convention, the class name should end with ‘Contract’. Include member variables and parm methods for each piece of data you need to pass to the process.


    [DataContractAttribute]
class SCCSysOperationDemoContract
{
    CustGroupId custGroupId;

    [DataMemberAttribute
        ,SysOperationLabelAttribute(literalStr("Customer group"))
        ,SysOperationHelpTextAttribute(literalStr("Customer group Id"))
        ,SysOperationDisplayOrderAttribute('1')]
    public CustGroupId parmCustGroupId(CustGroupId _custGroupId = custGroupId)
    {
        custGroupId = _custGroupId;
 
        return _custGroupId;
    }
}

    

Steps 2: Create Service Class

The service class is where the actual processing takes place. To create this in D365, start by making a new class that extends SysOperationServiceBase. For consistency, the class name should end with ‘Service’. Then, create a public method with a name of your choice that accepts a single parameter of the Contract class type.


    class SCCSysOperationDemoService extends SysOperationServiceBase
{
    public void processDemo(SCCSysOperationDemoContract _contract)
    {
        CustTable custTableUpdate;

        update_recordset custTableUpdate
            setting SCCActivateCustomer         = NoYes::Yes
              where custTableUpdate.CustGroup   == _contract.parmCustGroupId();

              Info("Activated the selected customer group successfully");
    }
}

    

Steps 3: Create Controller Class

The controller class configures the SysOperation Framework process. Create a new class in D365, that extends the class SysOperationServiceController.


    class SCCSysOperationDemoController extends SysOperationServiceController
{
    protected void new()
    {
        // This tells the controller what method it should execute as the service. In this case, we'll run SysOperationDemoService.processDemo()
        super(classStr(SCCSysOperationDemoService), methodStr(SCCSysOperationDemoService, processDemo), SysOperationExecutionMode::Synchronous);
    }

    public static SCCSysOperationDemoController construct()
    {
        SCCSysOperationDemoController controller;
 
        controller = new SCCSysOperationDemoController();
 
        controller.parmShowDialog(true); // Actually the default value
        controller.parmShowProgressForm(false);
 
        return controller;
    }

    public static void main(Args _args)
    {
        SCCSysOperationDemoController   controller;
 
        controller = SCCSysOperationDemoController::construct();
        controller.startOperation();
    }

    protected boolean validate()
    {
        SCCSysOperationDemoContract contract;
        CustTable                   custTable;
        boolean                     ret = true;
     
        contract = this.getDataContractObject();

        select firstonly custTable
            where custTable.CustGroup == contract.parmCustGroupId();

        if (!custTable)
        {
            // Failing the validate will not close the dialog, and the user will have another chance of inputting the correct values
            ret = checkFailed('Customer group must be filled in');
        }
     
        return ret;
    }

    protected ClassDescription defaultCaption()
    {
        //This will be the dialog's caption
        return 'SysOperation framework demo';
    }

}

    

⦁ new() Method: This method sets up the controller to execute the processDemo() method from SCCSysOperationDemoService synchronously (SysOperationExecutionMode::Synchronous).

⦁ construct() Method: A static method that initializes an instance of SCCSysOperationDemoController with default settings (parmShowDialog(true) and parmShowProgressForm(false)).

⦁ main() Method: Entry point for your operation. It constructs the controller and starts the operation.

⦁ validate() Method: Validates input before executing the operation. It checks if a customer group (parmCustGroupId()) exists in the CustTable table and returns false if not, displaying an error message.

⦁ defaultCaption() Method: Provides the default caption for the dialog shown during operation (‘SysOperation framework demo’).

Steps 4: Create Action Menu Item
Finally create action menu item to provide a user interface entry point to trigger the batch operation.

Output:
Run the batch in dialog by giving the parameter.

Activate customer field updated as Yes where Customer group is ‘10’