"Page load" scripts in BPM 8.x are coach view load handlers - the coach itself has no script slot, but any coach view placed on it runs its load when the page renders. Options from simplest to most controlled:
- A "Page Script" coach view: an empty custom coach view (no layout) with the code in its load event; drop it on every coach where it is needed, pass parameters as configuration options. Runs once per page load, after the DOM of the coach exists.
- The coach's own controls: the UI Toolkit controls have an On load event - put the page-level script on the top-level Vertical Layout's On load (it fires when the layout is ready); on older toolkits use a hidden control.
- Coach view load vs view: load fires once when the view is created, view (8.5.7+) every time it becomes visible - use view for scripts that must re-run when returning to a coach in a wizard.
// Page Script coach view - load handler
var _this = this;
// wait for the toolkit controls to be ready (they load in the same pass; use a tick to be safe)
setTimeout(function () {
var e = bpmext.ui.getView("Email"); // BPM UI Toolkit helper: find a control by id from anywhere on the page
if (e && !e.getData()) e.setData(_this.context.options.defaultEmail.get("value"));
document.title = "Order " + (bpmext.ui.getView("OrderNumber") || {}).getData();
}, 0);Heritage coaches (7.5-style) had a Custom HTML block where a <script> ran at load - the coach view load handler is its replacement. Avoid window.onload: the coach is rendered after the window has loaded, so it never fires for your script.
References