A coach view does not own its data; it gets a binding from the coach. Initialise in this order, whichever fits the case:
- Default value of the variable - in the CSHS, select tw.local.myVar and tick Has default (business objects get all their fields initialised; lists start empty). The view sees the value at load time.
- Script before the coach - a client-side script task in the CSHS flow: tw.local.order = { status: "NEW", lines: [] }.
- Inside the coach view when the binding is empty - in the view's load handler:
// coach view load event
var b = this.context.binding;
if (b && (b.get("value") === undefined || b.get("value") === null || b.get("value") === "")) {
b.set("value", this.context.options.defaultValue ? this.context.options.defaultValue.get("value") : "N/A");
}
// a complex binding: create the fields the view expects
var v = b.get("value");
if (v && v.status === undefined) b.set("value.status", "NEW");Rules that avoid surprises: never assign this.context.binding = ... (only set("value", ...) writes through to the coach data); for lists use b.get("value").add(item) or set("value", []); if the view must work unbound, guard every access with if (this.context.binding). Configuration options are the right place for defaults that differ per coach (defaultValue above) - the CSHS can bind them to variables or literals.
References