Monday 11 November 2013

AX 2012 SysOperation Framework vs RunBaseBatch


AX 2012 SysOperation Framework vs RunBaseBatch

 

 

The 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 Concepts:

1.       Data Contract Class:

a.       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.

b.      This class must be [DataContractAttribute] before declaration.

                                                               i.      Eg: [DataContractAttribute]

class MKTestDataContract

{

}

c.       This class must contain same number of parm methods as the number of input fields.

d.      All parm methods must start with [DataMemberAttribute]

                                                               i.      Eg: [DataMemberAttribute]

 

public int parmAge(int _age= age)

{

    age     = _age;

   return age;

}

                                                                               

2.       Service Operation Classes:

a.       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 Framwork.

b.      This class must be extend “SysOperationServiceController”.

c.       It should override “New” method and also have ‘main’ and “construct” methods.

 

Ex:

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.

1.       First create Data Contract class as below.

[DataContractAttribute]

class MKTestDataContract

{

    str         fName;

    str         lName;

    int         age;

    TransDate   dob;

    NoYesId     dobcheck;

}

2.       Add parm methods for the above input variables.

 

[DataMemberAttribute]

 

public str parmfName(str _fname = fName)

{

    fName   = _fname;

    return  fName;

}

 

[DataMemberAttribute]

 

public str parmlName(str _lName=lName)

{

    lName   = _lName;

    return  lName;

}

 

[DataMemberAttribute]

 

public TransDate parmDOB(TransDate _dob= dob)

{

    dob     = _dob;

    return dob;

}

 

[DataMemberAttribute]

 

public int parmAge(int _age= age)

{

    age     = _age;

    return age;

}

 

[DataMemberAttribute]

 

public NoYesId parmDobcheck(NoYesId    _dobcheck=dobcheck)

{

    dobcheck        = _dobcheck;

    return dobcheck;

}

 

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

 

class MKTestBatchServiceOperation extends SysOperationServiceController

{

}

4.       Override New method.

public void new(IdentifierName                               _className        = '',

 IdentifierName                                _methodName = '',

 SysOperationExecutionMode _executionMode = 0)

{

    super();

    this.parmClassName(_className);

    this.parmMethodName(_methodName);

    this.parmExecutionMode(_executionMode);

}

 

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

public void runMyLogic(MKTestDataContract _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));

}

6.       Create a construct method

public static MKTestBatchServiceOperation construct()

{

    ClassName className;

    MethodName runMethodName;

    SysOperationExecutionMode exeMode = SysOperationExecutionMode::Synchronous;

    MKTestBatchServiceOperation mkServiceOperation;

 

    className = classStr(MKTestBatchServiceOperation);

    runMethodName = methodStr(MKTestBatchServiceOperation, runMyLogic);

    mkServiceOperation = new MKTestBatchServiceOperation(className,runMethodName,exeMode);

    mkServiceOperation.parmDialogCaption("Mallik say SysOperation Batch");

    return mkServiceOperation;

 

}

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

public static void main(Args    _args)

{

    MKTestBatchServiceOperation mkServiceOperation;

    mkServiceOperation          = MKTestBatchServiceOperation::construct();

    mkServiceOperation.startOperation();

}

8.       Generate Incremental CIL. This is required as it will be executed on AOS server.

9.       Run the above class and enter inputs and see output J!!!!.. Mallik

 

 

1 comment:

Anonymous said...

Very useful, thank you very much. Nice place to start with this complicated framework.
Petr Široký

Update NuGet package to new MS D365FO version

1. Import the NuGet package files from LCS for that particular version please take the PU version files only. a. Goto LCS-->Asset Libra...