0 votes
635 views
in BPD by (21.5k points)

1 Answer

0 votes
by (30.6k points)

ANY is the System Data type that can hold any value (string, number, business object, list, Map, Record). It is the tool for generic services - message routers, integration facades, dynamic forms - as long as you convert to typed objects as soon as the structure is known. Working techniques:

// 1. inspect what you got (server-side script)
var v = tw.local.payload;                                    // ANY
var kind = (v == null) ? "null" : (v.listLength !== undefined ? "list" : (typeof v == "object" ? (v.constructor && v.constructor.name) || "object" : typeof v));

// 2. generic access by property name
function get(obj, path) { return path.split(".").reduce(function (o, k) { return (o == null) ? o : o[k]; }, obj); }
var customerName = get(tw.local.payload, "customer.name");

// 3. JSON in / JSON out: the safest generic contract
tw.local.json = JSON.stringify(tw.local.payload);             // BOs serialise on BAW 20+ (older releases: toXML() or build the object by hand)
var obj = JSON.parse(tw.local.json);                          // plain JS object -> Record-like access

// 4. convert to a typed BO when you know the type
var order = new tw.object.Order();
for (var k in obj) if (order[k] !== undefined) order[k] = obj[k];
tw.local.order = order;

// 5. dynamic forms: a Record bound in a coach
var rec = new tw.object.Record(); rec.field1 = "x"; rec.amount = 5; tw.local.form = rec;   // coach controls bind to tw.local.form.field1

Rules: (a) ANY variables cannot be bound to coach controls directly - bind their fields (tw.local.form.field1) or convert; (b) ANY in service interfaces makes the designer unable to validate mappings - document the expected structure; (c) lists of ANY need insertIntoList with typed elements; (d) on BAW 20+ JSON.stringify on business objects works; on 8.5.x use the XML serialisation (toXML()) or the Record + JSON path. Keep ANY at the boundaries and typed objects inside.

References

Related questions

0 votes
1 answer 3.6k views
0 votes
1 answer 624 views
0 votes
1 answer 849 views
0 votes
1 answer 725 views
0 votes
1 answer 1.0k 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
...