0 votes
847 views
in Integrations by

1 Answer

0 votes
by (30.6k points)

The SQL Execute Statement integration takes a returnType parameter (the business object name) and maps columns to fields by name automatically - by exact name, case-insensitive, without any transformation (CUSTOMER_NAME does not become customerName); so name the fields like the columns or alias the columns in the SELECT:

-- service flow: SQL Execute Statement with returnType = "Order" (BO fields: number, customer, total, created)
select ORDER_NO as "number", CUSTOMER_NAME as "customer", TOTAL_AMOUNT as "total", CREATED_TS as "created"
  from ORDERS where STATUS = ?
-- parameters: tw.local.params (SQLParameter list: value = tw.local.status, type = VARCHAR)
-- output: tw.local.orders (list of Order) - every row becomes an Order with the aliased columns

Rules: alias every column to the field name (quoted aliases keep the case on Db2 / Oracle; SQL Server is case-insensitive); columns with no matching field are ignored, fields with no column stay null; types must be compatible (numeric to Decimal / Integer, TIMESTAMP to Date, VARCHAR to String); for SELECT * either name the table columns like the fields (a view is the elegant way: create a database view with the aliases once, then select * from V_ORDERS) or leave returnType empty - the service then returns generic result rows (one Record-like object per row with the column names as properties) that you convert in a script:

// generic rows -> typed BOs when aliasing is not possible
tw.local.orders = new tw.object.listOf.Order();
for (var i = 0; i < tw.local.rows.listLength; i++) {
  var r = tw.local.rows[i], o = new tw.object.Order();
  o.number = r.ORDER_NO; o.customer = r.CUSTOMER_NAME; o.total = r.TOTAL_AMOUNT; o.created = r.CREATED_TS;
  tw.local.orders.insertIntoList(i, o);
}

Nested objects (customer.name) cannot be auto-mapped from flat rows - map them in a script or use two queries; large result sets should be paged in SQL (FETCH FIRST n ROWS ONLY / OFFSET) because every row becomes a BAW object in memory.

References

Related questions

0 votes
1 answer 3.6k views
0 votes
1 answer 2.0k views
0 votes
1 answer 760 views
+1 vote
1 answer 1.2k views
0 votes
1 answer 1.3k views
0 votes
1 answer 1.1k views
0 votes
1 answer 873 views
0 votes
1 answer 1.8k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.8k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...