Batch Processing in Dynamics AX 2012 Using SysOperation Framework

By Ramesh Singh | March 27, 2017

Batch processing in dynamics ax 2012 using sysoperation framework

In Microsoft Dynamics AX 2012, SysOperation framework replaced RunBase framework to support the batch processing functionality. Going forward, SysOperation framework is recommended for writing custom business logic that requires batch processing functionality, over the deprecated RunBase framework.

The RunBase framework defines coding patterns that implement these requirements. The SysOperation framework provides base implementations for many of the patterns defined by the RunBase framework. Another great thing is SysOperation framework simplified the pack / unpack of variables that was additional work in the RunBase framework, taking advantage of the Attributes feature introduced with AX 2012. For a detailed comparison between SysOperation and RunBase framework, refer to Microsoft Dynamics AX 2012 White Paper: Introduction to the SysOperation Framework.

SysOperation framework allows application logic to be written in a way that supports running operations interactively or via the Microsoft Dynamics AX batch server. It implements the MVC (Model–View–Controller) design pattern, with the isolation of Parameters (Model), Dialog (View) and Service (Controller), for the code that’s executed.

The key objects of the framework are defined below:

Service: Service class extends from the SysOperationServiceBase class and contains the business logic for the batch operation. Developers often tend to add the business logic in controller classes, which violates the Single responsibility principle.

Data Contract: Data contract class is the model class defining attributes needed for batch operations. These attributes are provided by the user, in a dialog. DataContractAttribute attribute is needed for the class and the properties methods requires DataMemberAttribute attribute.

Controller: Controller class extends from the SysOperationServiceController class. It holds information about the batch operation like execution mode, show dialog or progress bar etc. and directs the batch operation.

UI Builder: UI Builder class extends from SysOperationAutomaticUIBuilder class and is used for adding custom behavior to dialog / dialog fields dynamically constructed by the SysOperation framework.

In this blogpost, I’ll cover three different scenarios (in a sequential manner) for creating batch operations using SysOperation framework classes – Service, Data Contract, Controller and UI Builder.

Scenario 1: Creating a simple batch operation

Project: SharedProject_SysOperation_SimpleBatchOperation.xpo

Creating a simple batch operation

Running batch operation

1. Controller Class

public class SysOperationControllerClass extends SysOperationServiceController
{
}

public void new()
{
    super();
    
    this.parmClassName(classStr(SysOperationServiceClass));
    this.parmMethodName(methodStr(SysOperationServiceClass, processOperation));
    
    this.parmDialogCaption("Batch Operation Dialog Title");
}

public ClassDescription caption()
{
    return "Batch Operation Task Description";
}

public static void main(Args args)
{
    SysOperationControllerClass controller;
    
    controller = new SysOperationControllerClass();
    controller.startOperation();
}

2. Service Class

public class SysOperationServiceClass extends SysOperationServiceBase
{
}

public void processOperation()
{
    info ("Running SysOperation Batch Operation");
}

3. Optional: Menu item

Type: Action menu item
Object type: Class
Object: SysOperationControllerClass

Scenario 2: Add user defined parameters for batch operation

Project: SharedProject_SysOperation_UserDefinedParmsBatchOpr.xpo

Add user defined parameters for batch operation

Add user defined parameters for batch operation

1. Controller Class

public class SysOperationControllerClass extends SysOperationServiceController
{
}

public void new()
{
    super();
    
    this.parmClassName(classStr(SysOperationServiceClass));
    this.parmMethodName(methodStr(SysOperationServiceClass, processOperation));
    
    this.parmDialogCaption("Batch Operation Dialog Title");
}

public ClassDescription caption()
{
    return "Batch Operation Task Description";
}

public static void main(Args args)
{
    SysOperationControllerClass controller;
    
    controller = new SysOperationControllerClass();
    controller.startOperation();
}

2. Service Class

public class SysOperationServiceClass extends SysOperationServiceBase
{
}

public void processOperation(SysOperationDataContractClass _contract)
{
    info ("Running SysOperation Batch Operation");
    
    info ("Date Property: " + date2Str
            (_contract.parmDate(),
            213,
            DateDay::Digits2,
            DateSeparator::Dot, 
            DateMonth::Long,
            DateSeparator::Dot, 
            DateYear::Digits4));
    
    info ("Text Property: " + _contract.parmText());
}

3. Data Contract Class

[DataContractAttribute]
public class SysOperationDataContractClass
{
    TransDate      dateValue;
    Description255 textValue;
}


public TransDate parmDate(TransDate _dateValue = dateValue)
{
    dateValue = _dateValue;
    return dateValue;
}


public Description255 parmText(Description255 _textValue = textValue)
{
    textValue = _textValue;
    return textValue;
}

4. Optional: Menu item

Type: Action menu item
Object type: Class
Object: SysOperationControllerClass

Scenario 3: Add custom validation to dialog fields

Project: SharedProject_SysOperation_UserParmsValidationBatchOpr.xpo

Scenario 3.1 – Validation failed:

Add custom validation to dialog fields - Validation Failed

Add custom validation to dialog fields - Validation Failed

Scenario 3.2 – Validation passed:

Add custom validation to dialog fields - Validation Passed

Add custom validation to dialog fields - Validation Passed

1. Controller Class

public class SysOperationControllerClass extends SysOperationServiceController
{
}

public void new()
{
    super();
    
    this.parmClassName(classStr(SysOperationServiceClass));
    this.parmMethodName(methodStr(SysOperationServiceClass, processOperation));
    
    this.parmDialogCaption("Batch Operation Dialog Title");
}

public ClassDescription caption()
{
    return "Batch Operation Task Description";
}

public static void main(Args args)
{
    SysOperationControllerClass controller;
    
    controller = new SysOperationControllerClass();
    controller.startOperation();
}

2. Service Class

public class SysOperationServiceClass extends SysOperationServiceBase
{
}

public void processOperation(SysOperationDataContractClass _contract)
{
    info ("Running SysOperation Batch Operation");
    
    info ("Date Property: " + date2Str
            (_contract.parmDate(),
            213,
            DateDay::Digits2,
            DateSeparator::Dot, 
            DateMonth::Long,
            DateSeparator::Dot, 
            DateYear::Digits4));
    
    info ("Text Property: " + _contract.parmText());
}

3. Data Contract Class

[DataContractAttribute,
 SysOperationContractProcessingAttribute(classStr(SysOperationUIBuilderClass))]
public class SysOperationDataContractClass
{
    TransDate      dateValue;
    Description255 textValue;
}


public TransDate parmDate(TransDate _dateValue = dateValue)
{
    dateValue = _dateValue;
    return dateValue;
}


public Description255 parmText(Description255 _textValue = textValue)
{
    textValue = _textValue;
    return textValue;
}

4. UI Builder Class

public class SysOperationUIBuilderClass extends SysOperationAutomaticUIBuilder 
{
    DialogField dateField;
}

public void postBuild()
{
    super();
    
    // get references to dialog controls after creation
    dateField = this.bindInfo().getDialogField(this.dataContractObject(), 
                                    methodStr(SysOperationDataContractClass, parmDate));
}

public void postRun()
{
    super();
    
    // register overrides for form control events
    dateField.registerOverrideMethod(methodstr(FormDateControl, validate), 
                methodstr(SysOperationUIBuilderClass, validateDate), this);
}

public boolean validateDate(FormDateControl _dateControl)
{
    if (_dateControl.dateValue() > today())
    {
        error("Please select a past date");     
        return false;
    }

    return true;
}

5. Optional: Menu item

Type: Action menu item
Object type: Class
Object: SysOperationControllerClass

Download the project .xpo(s) to import here:

SharedProject_SysOperation.zip (1627 downloads)

Related Posts

Recommended Reading:

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article
5.5.22 Dynamics GP

The Real Story about the Long-Term Future of Dynamics GP Support

I’ve seen a number of people put forward comment that Dynamics GP is going away and you have to get […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Financial Enhancements

The Dynamics 365 Businses Central 2022 Wave 1 Release has a lot of new and exciting features to help your […]

Read the Article
4.29.22 Dynamics GP

Dynamics GP Transaction Removals: Bank Reconciliation

  This is part 2 of a 3 part series on Dynamics GP Transaction Removals. These quick tips will hopefully […]

Read the Article
4.28.22 Dynamics GP

Uncommonly Used Features – Integrate Purchasing and Payables to Fixed Assets in Dynamics GP

Being able to integrate Purchasing and Payables to Fixed Assets in Dynamics GP will help you create visibility for your […]

Read the Article

New Features in the Dynamics 365 Business Central 2022 Wave 1 Release – Ease-of-Use Features

  There are many new features in the Dynamics 365 Business Central 2022 Wave 1 Release to get excited about! […]

Read the Article

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X