Search This Blog

Friday, September 9, 2011

AX2012 BOF (Business operation framework)

Business Operation Framework (BOF) [AX 2012]
The Business Operation Framework service is one of the system services exposed by Microsoft Dynamics AX and that adheres to the Windows Communication Foundation (WCF) protocols and standards.
This service enables you to  develop the Service and attach that service to BOF

·         Allows menu-driven execution or batch execution of services.
·         Calls services in synchronous or asynchronous mode.
·         Automatically creates a customizable UI based on the data contract.
·         Encapsulates code to operate on the appropriate tier (prompting on the client tier, and business logic on the server tier).

SysOperationServiceController
ServiceClassName
SysOperationExecutionMode
Enums

Overview
To create a Business Operation Framework service, the following steps must be performed.
·         Create a data contract class
·         Identify the parameters passed to the service
·         Register the class as a Business Operation Framework service
·         Optionally customize the automatically generated UI for the class
Create a data contract class
Create one or more classes to define the parameters for the operation.
The X++ attribute [DataContractAttribute] identifies the class as a data contract class.

[DataContractAttribute]
class SimpleDataContract
{
    int property1;
    str property2;
}
Identify parameters
The X++ attribute [DataMemberAttribute] identifies the property accessor methods, which are the parameters to the service call.

[DataMemberAttribute]
public int property1(int _property1 = property1)
{
    property1 = _property1;
    return property1;
}

[DataMemberAttribute]
public str property2(str _property2 = property2)
{
    property2 = _property2;
    return property2;
}
The data contract class can have properties that return data contract classes for more complex scenarios.
Register service
After the data contract classes are defined, creating the service operation is simple.

class SimpleService
{
}

public str operation1(SimpleDataContract _dataContract)
{
    str returnValue;

    returnValue = strfmt('Input was %1, %2',
        _dataContract.property1(),
        _dataContract.property2());

    return returnValue;
}
To register this class as a service, the following steps must be performed.
1.       The class must be marked to run on the server.
2.       The class must be registered in Application::registerServices.

void registerServices()
{

    xApplication::addXppService(new DictClass(classnum(SimpleService)));
}

Generate and customize the UI for the class
When the Business Operation Framework service executes, the framework will automatically generate a UI for the operation by reflecting on the data contract class and building a dialog. No further work is required if the generated UI is adequate.
However, if you wish to modify the automatically generated UI, you can make those modifications two ways: Attribute-based customization and code-based customization.
Attribute-based UI customization
In most scenarios attribute based customization is sufficient.
To add a UI group for the parameters, add a SysOperationGroupAttribute to the DataContractAttribute:

[DataContractAttribute,
    SysOperationGroupAttribute('group1', "@SYS1001", '1')]
class SimpleDataContract
{
    int property1;
    str property2;
}
To order property2 before property1 within group1, and use labels on both properties:
[DataMemberAttribute,
    SysOperationGroupMemberAttribute('group1'),SysOperationLabelAttribute('SYS1002'),SysOperationHelpTextAttribute('SYS1003'),SysOperationDisplayOrderAttribute('2')]
public int property1(int _property1 = property1)
{
    property1 = _property1;
    return property1;
}

[DataMemberAttribute,
    SysOperationGroupMemberAttribute('group1'),SysOperationLabelAttribute('SYS3000'),SysOperationHelpTextAttribute('SYS301868'),SysOperationDisplayOrderAttribute('1')]
public str property2(str _property2 = property2)
{
    property2 = _property2;
    return property2;
}
Code-based UI customization
Note: I could not find information in the spec on code-based UI customization.
 
A Business Operation Framework service can be called in four ways:
As a menu item or as a batch process. And it can be called synchronously or asynchronously.
To call a Business Operation Framework service from a menu item
1.       Create an Action Menu Item
2.       Set the ObjectType to Class
3.       Set the Object to SysOperationServiceController
4.       Set the Parameters to <ServiceClassName>.<MethodName>
To call a Business Operation Framework service as a batch operation
To execute a batch operation:
static void Job2(Args _args)
{
    SimpleDataContract parameters = new SimpleDataContract();
    SimpleService service = new SimpleService();
    str returnValue;
   
    parameters.property1(99);
    parameters.property2('Hello World');
   
    returnValue = service.operation1(parameters);
    info(returnValue);
}
To call a Business Operation Framework service synchronously
To run the service synchronously, edit the menu item:
1.       Set the EnumTypeParameter to SysOperationExecutionMode
2.       Set the EnumParameter to Synchronous
After the service operation is complete, the result will be displayed in the InfoLog.
To call a Business Operation Framework service asynchronously
To run the service asynchronously, edit the menu item:
1.       Set the EnumTypeParameter to SysOperationExecutionMode
2.       Set the EnumParameter to Asynchronous
After the service operation is complete, the result will be displayed in the InfoLog.

2 comments:

  1. Hi, As per the above example, I have created the classes but I am not able to register the service. I want to see the service in System administrator - Setup - Services And Application Framework - Inbound Ports. How to do that ? Please explain.

    I have already tried to deployed the service but it gives error.

    ReplyDelete
    Replies
    1. Hi Anus,
      Normally if you want to do that add this service class to service group and deploy the service group the automatically it will activate the service in system administrator setup aif services. if not you can create the inbound post manually by selecting the service that you created with the operation as inbound port. I hope you understand, if not please ping me on krishna.dynamics@gmail.com

      Delete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.