0 votes
1.8k views
in Coach Views by

1 Answer

0 votes
ago by (30.6k points)

Environment variables live on the server; a coach view runs in the browser, so the value has to be handed over. Three ways, from cleanest to quickest:

  1. Configuration option: the CSHS reads tw.env.myVar in a server-side step (a service flow called at the start of the CSHS, since client-side scripts have no tw.env) into tw.local.config, and the coach view gets it through a configuration option bound to that variable - the view reads this.context.options.baseUrl.get("value"). Reusable and testable.
  2. Coach-level variable: same, but the coach view reads page data through a hidden control or its binding (this.context.binding.get("value") when bound to tw.local.config).
  3. Ajax service from the view: a service flow with no input that returns the environment variables the UI may see (never secrets), called by a Service Call or the view's Service option at load; cached in a global for other views.
// service flow "Get UI config" (server side): whitelist what the browser may know
tw.local.config = new tw.object.UiConfig();
tw.local.config.reportUrl = tw.env.reportUrl;
tw.local.config.maxUploadMb = parseInt(tw.env.maxUploadMb, 10);
// CSHS: first step calls it; coach view "Uploader" has an option maxUploadMb bound to tw.local.config.maxUploadMb
// coach view load handler:
var max = this.context.options.maxUploadMb.get("value") || 10;

Do not try tw.env in client-side scripts or coach view code - it is undefined there (the classic symptom is "tw.env is not defined" in the browser console). Keep secrets (passwords, API keys) on the server: pass only what the UI needs. On CP4BA the mechanism is identical; only the values are set per Workflow Server in Process Admin.

References

Related questions

0 votes
1 answer 1.7k views
0 votes
1 answer 2.4k views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.0k views
0 votes
1 answer 2.1k views
0 votes
1 answer 782 views
asked Aug 31, 2019 by Anil Singh (30.6k points)
0 votes
1 answer 1.6k views
0 votes
1 answer 1.2k views
0 votes
1 answer 1.7k views
0 votes
1 answer 1.3k views
0 votes
1 answer 1.9k views
0 votes
2 answers 1.8k views
0 votes
1 answer 1.1k views
0 votes
2 answers 2.9k views
0 votes
1 answer 931 views
0 votes
1 answer 3.0k views
asked Nov 8, 2018 by BPM Tips Admin (21.5k points)

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
...