AX 2012 – Business Operation Framework - Create Batch without using RunBaseBatch Framework - Part I

 

Introduction:

You can develop components / write business logic and later can be hosted as services on AOS with help of Windows communication foundation. These services later can be used by or integrated with the third party applications in order to communicate with Dynamics AX.

BOF Artifacts:

Data Contract Class:

By name only you can identify that this class is going to hold input parameters and query. In simple terms these are fields/controls which we add on ‘Dialog’ to get input from user like FromDate, query criteria’s through select button.

To identify class as Data Contract, we need to use [DataContractAttribute] as below,

And for parm methods, [DataMemberAttribute]

Note:Thumb rule, if you have 10 fields on ‘Dialog’ then you should have 10 parm method.

Service Operation Class:

This class contains main business logic for which you designed/create ‘Data Contract’ class.

UI Builder Class:

BOF automatically generates ‘Dialog UI’ based upon Data Contract class, but if we wanted to access dialog fields at run time for validations like ‘enabled/allowEdit/Lookup’ then we need to create separate class for user interface.

Let us follow below steps in order to create batch class without using ‘RunBaseBatch’ framework, instead we make use of new BOF framework.

Step1:

Create Data Contract class as below,

  1. [DataContractAttribute]
  2. class Tutorial_TestDataContract
  3. {
  4. TransDate transDate;
  5. CustAccount custAccount;
  6. }

For each variable, create parm method and add [DataMemberAttribute] as below,

  1. [DataMemberAttribute]
  2. public TransDate parmTransDate(TransDate _transDate = transDate)
  3. {
  4. transDate = _transDate;
  5. return transDate;
  6. }

//

  1. [DataMemberAttribute]
  2. public CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
  3. {
  4. custAccount = _custAccount;
  5. return custAccount;
  6. }

Step 2:

Once you done with data contract class,  create class to write business logic which will make use of above input parameters. It’s like ‘run’ method of any batch class where we write actual business logic.

  1. class Tutorial_TestBatchServiceOperation extends SysOperationServiceController
  2. {
  3. }

Create ‘new’ method as below

  1. public void new(identifierName _className = "", identifierName _methodName = "", SysOperationExecutionMode _executionMode = 0)
  2. {
  3. super();
  4. this.parmClassName(_className);
  5. this.parmMethodName(_methodName);
  6. this.parmExecutionMode(_executionMode);
  7. }

Create ‘Construct’ method as below

  1. public static Tutorial_TestBatchServiceOperation construct()
  2. {
  3. ClassName className;
  4. MethodName runMethodName;
  5. SysOperationExecutionMode execMode = SysOperationExecutionMode::Synchronous;
  6. Tutorial_TestBatchServiceOperation testBatchServiceOp;
  7. className = classStr(Tutorial_TestBatchServiceOperation);
  8. runMethodName = methodStr(Tutorial_TestBatchServiceOperation, runMyLogic);
  9. testBatchServiceOp = new Tutorial_TestBatchServiceOperation(className,
  10. runmethodName,
  11. execMode);
  12. testBatchServiceOp.parmDialogCaption("Tutorial SysOperation Batch");
  13. return testBatchServiceOp;
  14. }

//Method which will act as entry point to your business logic

//You can compare this method to 'run' method of any class

  1. public void runMyLogic(Tutorial_TestDataContract _data)
  2. {
  3. ;
  4. info(strFmt("You entered %1, %2", _data.parmCustAccount(), _data.parmTransDate()));
  5. }

Finally main method to make class to run

  1. public static void main(Args args)
  2. {
  3. Tutorial_TestBatchServiceOperation testBatch;
  4. testBatch = Tutorial_TestBatchServiceOperation::construct();
  5. testBatch.startOperation();
  6. }

Step3:

It’s very important to run ‘Incremental CIL Generation’ since above class will get executed on AOS.

Step4:

Run above class ‘Tutorial_TestBatchServiceOperation ‘ and you can see similar/familiar user interface for batch class

image

Click ‘Ok’ and you will get output as below

image

In next part will try to address how to access fields on dialog at run-time to control validations like ‘allowEdit/enabled’ etc….

Untill then ‘Happy Batching :) ‘