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.field1Rules: (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