How to Create SysOperationFramework in Ax 2012

Description:- 

In AX 2012 the RunBaseBatch Framework has been replaced with SysOperation framework formally known as Business Operation Framework. We can still use the RunBaseBatch framework in AX 2012, but is recommended to use SysOperation Framework.

SysOperation Framework:- SysOperation Framework formerly known as (Business Operation Framework) provides a way to create and run our operations on a batch server. Previously in earlier versions of Ax 2009 RunBaseBatch framework was used.

The only reason that I have understand of the introduction of SysOperation in Ax 2012 is that, in previous version RunBaseBatch provides the implementation of the actions required for the operation to be run on server. But SysOperation provides the BASE implementation of all the implementation that were before. So it means that there is a fair chance of extending in future versions as well.

SysOperation Concept:

Data Contract Class
 This class is used for holding the input data. As the name indicates this class is used to take the inputs from the user and will store in to variables.
This class must be [DataContractAttribute] before declaration.
This class must contain same number of parm methods as the number of input fields.
All parm methods must start with [DataMemberAttribute] 
Eg: [DataMemberAttribute]

  
Server Operation Classes
This class is used to run the business logic for the data contract class, we can say it is similar to "run" method in the RunBaseBatch Framework.
This class must be extend "SysOperationServiceController".
It should override “New” method and also have ‘main’ and “construct” methods.


In the below example we will create a dialog to take inputs from user and display info log.
Inputs: First Name, Last Name, DOB and age.

Create Data Contract Class as below.

[DataContractAttribute]
class UmeshTestDataContract
{
    str         fName;
    str         lName;
    int         age;
    TransDate   dob;
    NoYesId     dobcheck;
    str title;
}

[DataMemberAttribute]
public int parmAge(int _age= age)
{
    age     = _age;
    return age;
}

[DataMemberAttribute]
public TransDate parmDOB(TransDate _dob= dob)
{
    dob     = _dob;
    return dob;
}

[DataMemberAttribute]
public NoYesId parmDobcheck(NoYesId    _dobcheck=dobcheck)
{
    dobcheck        = _dobcheck;
    return dobcheck;
}

[DataMemberAttribute]
public str parmfName(str _fname = fName)
{
    fName   = _fname;
    return  fName;
}

[DataMemberAttribute]
public str parmlName(str _lName=lName)
{
    lName   = _lName;
    return  lName;
}

Now we will create a serviceOperation class, which will extend SysOperationServiceController.

class UmeshTestBatchServiceOperation extends SysOperationServiceController
{
}

Override New method.

public void new(IdentifierName _className  = '', IdentifierName _methodName = '', SysOperationExecutionMode _executionMode = 0)
{
    super();
    this.parmClassName(_className);
    this.parmMethodName(_methodName);
    this.parmExecutionMode(_executionMode);
}

Create a method to run the business logic as Run method in the RunBaseBatch.

public void runMyLogic(UmeshTestDataContract _datacontract)
{
    VendTable       lVentTable;
    str             name;
    TransDate       ldob;
    int             lage;
    name            = _datacontract.parmfName() + " " + _datacontract.parmlName();
    ldob            = _datacontract.parmDOB();
    lage            = _datacontract.parmAge();
    info(strFmt("%1 : %2 : %3",name, ldob, lage));
}

Create a construct method

public static UmeshTestBatchServiceOperation construct()
{
    ClassName className;
    MethodName runMethodName;
    SysOperationExecutionMode exeMode = SysOperationExecutionMode::Synchronous;
    UmeshTestBatchServiceOperation UkServiceOperation;
    className = classStr(UmeshTestBatchServiceOperation);
    runMethodName = methodStr(UmeshTestBatchServiceOperation, runMyLogic);
    UkServiceOperation = new UmeshTestBatchServiceOperation(className,runMethodName,exeMode);
    UkServiceOperation.parmDialogCaption("SysOperation Batch");
    return UkServiceOperation;
}

Now we will create a main method which will call the SysOperationServiceController method “startOperation”.

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

Generate Incremental CIL. This is required as it will be executed on AOS server.
Run the above class and enter inputs and see output.

Related Posts

Previous
Next Post »

Thanks for comments.....