transformCurrentRow Method

transformCurrentRow Method
lac52
You can use resources for mapping and translation, leveraging their ability to choose/rename attributes and related objects. 
CA Live API Creator
 has access to the (table) row by way of the 
logicContext
 object's 
transformCurrentRow()
 method. This method provides the transformation logic to choose/rename attributes and related objects. It transforms a table row to a resource instance as a JSON string.
You typically call this method in an event rule.
For more information about event rules, see Event Rule Types.
This method plays a central role in typical business-to-business interactions. This article illustrates the concepts of using this object using the the Business to Business (B2B) sample.
For more information about the B2B sample, see B2B API Sample.
In this article:
 
 
2
 
 
Transform Table Rows to Resource Instances
The following sections show how to transform a table row to a resource instance as a JSON string by way of resources and code. The following underlying concepts make this possible:
  • Row processing, particularly resource/object mapping, and logic.
For more information about row processing, see Row Objects.
  • The 
    transformCurrentRow()
     method.
    The following image shows the workflow for this method:
 
Partner Order: "Catch" Webhook
The 
PartnerOrder
 resource in the 
B2B Northwind
 API sample contains multiple tables. The columns that we want are chosen/renamed. The 
transformCurrentRow()
 method provides the following interface logic.
Automatic Generated Key Handling
Consider inserting a 
PartnerOrder
. When order details are inserted into the database, their OrderID foreign keys must be valid. But Partners cannot and should not provide OrderIDs. OrderIDs are internal implementation. Order numbers are are generated by the database management system (DBMS) on INSERT. 
CA Live API Creator
 provides automatic key generation services to obtain the OrderID and cascade the value into the Items objects. This process is automatic and based on schema information about keys and the resource join definition.
For more information about how 
CA Live API Creator
 returns the key in update responses, see Automatic Key Generation.
Business Logic: "Throw" Webhook
As a part of row processing, 
CA Live API Creator
 finds the relevant logic. For this transaction, the 
B2B Northwind
 API sample includes the 
Process Shipper WebHook
 commit event rule.
For more information about commit event rules, see Event Rule Types.
The ShipperAPIDef Resource
The 
ShipperAPIDef
 resource defines what tables we want, what attributes, and how they are renamed. This is the "shape" of the POST that we want to send to our shipper. The 
transformCurrentRow()
 method takes the current Order row (contained in the 
logicContext
 object) and creates an instance of it per the 
ShipperAPIDef
 resource. As for the incoming 
PartnerOrder
, resources define the mapping and transformation logic. The next line sends it to the address maintained in the shipper row.
transformCurrentRow() Method Operation
CA Live API Creator
 retrieves the value of a specified resource using this method (and associated metadata) and the 
SysUtility
 object's 
getResource()
 method.
The input row is passed by way of the 
logicContext
 object. It is a 
table
 row and 
not
 the resource row from the incoming request. That ensures that 
CA Live API Creator
 can reuse your business logic over the resources that are defined over that table, and regardless of the attributes they contain.
CA Live API Creator
 retrieves the value by supplying the primary key from the row. The 
getResource()
 method performs the mapping and transformation logic. There may be little or no correlation between table rows and the resource definition.
For more information: