1 Context:
In this example, we will implement an ABL Business Task, which will provide information regarding a specific customer. (ex. number of orders, number of shipped orders and the balance)
2 Step by step guide:
- Create a BusinessTask class in
src/backend/Training/
, with the nameCustomerTask.cls
- Generate the business task definition using the
b1-logicClass
snippet: - Create a BusinessTask Method Parameter class
src/backend/Training/GetCustomerDataParameter.cls
- Generate its definition using the
b1-logicParameter
snippet - Adjust the properties of the class to:
- Add references to the parameter in the business task class, by replacing
myParameterObject
withTraining.GetCustomerDataParameter
- Change the method name from
myMethod
toGetCustomerData
: - Add the logic to fetch the information and return it:
- After trimming the PASOE, the Business Task can be invoked using the following call:
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.CustomerTask
IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
"myMethod", GET-CLASS(myParameterObject)).
RETURN oCatalog.
END METHOD.
METHOD PUBLIC VOID myMethod(poParameter AS myParameterObject):
// enter your code here
END METHOD.
END CLASS.
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.GetCustomerDataParameter
INHERITS Consultingwerk.JsonSerializable:
/* Input properties */
{ Akioma/Swat/JsonSerializableProperty.i InputProperty LOGICAL }.
/* Output properties */
{ Akioma/Swat/JsonSerializableProperty.i OutputProperty LOGICAL }.
{ Akioma/Swat/JsonSerializableProperty.i Message CHARACTER }.
END CLASS.
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.GetCustomerDataParameter
INHERITS Consultingwerk.JsonSerializable:
/* Input properties */
{ Akioma/Swat/JsonSerializableProperty.i CustomerNumber INTEGER }.
/* Output properties */
{ Akioma/Swat/JsonSerializableProperty.i TotalOrders INTEGER }.
{ Akioma/Swat/JsonSerializableProperty.i ShippedOrders INTEGER }.
{ Akioma/Swat/JsonSerializableProperty.i Balance INTEGER }.
END CLASS.
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.CustomerTask
IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
"myMethod", GET-CLASS(Training.GetCustomerDataParameter)).
RETURN oCatalog.
END METHOD.
METHOD PUBLIC VOID myMethod(poParameter AS Training.GetCustomerDataParameter):
// enter your code here
END METHOD.
END CLASS.
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.CustomerTask
IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
"GetCustomerData", GET-CLASS(Training.GetCustomerDataParameter)).
RETURN oCatalog.
END METHOD.
METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
// enter your code here
END METHOD.
END CLASS.
METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
DEF VAR iCount AS INT NO-UNDO.
DEF VAR iNumShipped AS INT NO-UNDO.
DEFINE BUFFER bCustomer FOR sportsdb.customer.
DEFINE BUFFER bOrder FOR sportsdb.order.
FIND bCustomer WHERE bCustomer.CustNum EQ poParameter:customerNumber.
ASSIGN iCount = 0 iNumShipped = 0.
// for each fetched Customer, go through all contacts in the DB
FOR EACH bOrder WHERE bOrder.custNum = poParameter:CustomerNumber NO-LOCK:
iCount = iCount + 1.
IF bOrder.orderStatus = "Shipped" THEN ASSIGN iNumShipped = iNumShipped + 1.
END.
poParameter:TotalOrders = iCount.
poParameter:ShippedOrders = iNumShipped.
poParameter:Balance = bCustomer.Balance.
END METHOD.
b1.v1.App.invokeServerTask({
name: "Training.CustomerTask",
methodName: "GetCustomerData",
paramObj: { plcParameter: { CustomerNumber: 82 } }
})
Full Code Example:
BLOCK-LEVEL ON ERROR UNDO, THROW.
CLASS Training.CustomerTask
IMPLEMENTS Consultingwerk.OERA.IBusinessService, Consultingwerk.OERA.IBusinessTaskCatalogInfo:
METHOD PUBLIC Consultingwerk.OERA.IBusinessTaskCatalogData GetCatalogData():
DEFINE VARIABLE oCatalog AS Consultingwerk.OERA.BusinessTaskCatalogData NO-UNDO.
oCatalog = NEW Consultingwerk.OERA.BusinessTaskCatalogData(THIS-OBJECT:GetClass():TypeName,
"GetCustomerData", GET-CLASS(Training.GetCustomerDataParameter)).
RETURN oCatalog.
END METHOD.
METHOD PUBLIC VOID GetCustomerData(poParameter AS Training.GetCustomerDataParameter):
DEF VAR iCount AS INT NO-UNDO.
DEF VAR iNumShipped AS INT NO-UNDO.
DEFINE BUFFER bCustomer FOR sportsdb.customer.
DEFINE BUFFER bOrder FOR sportsdb.order.
FIND bCustomer WHERE bCustomer.CustNum EQ poParameter:customerNumber.
ASSIGN iCount = 0 iNumShipped = 0.
// for each fetched Customer, go through all contacts in the DB
FOR EACH bOrder WHERE bOrder.custNum = poParameter:CustomerNumber NO-LOCK:
iCount = iCount + 1.
IF bOrder.orderStatus = "Shipped" THEN ASSIGN iNumShipped = iNumShipped + 1.
END.
poParameter:TotalOrders = iCount.
poParameter:ShippedOrders = iNumShipped.
poParameter:Balance = bCustomer.Balance.
END METHOD.
END CLASS.
3 Explanation:
In contrast to the server event handler, the business task methods act as endpoints which allow custom complex logic to be handled, independent of any data source.