0 votes
1.2k views
in Coach Views by (30.6k points)

1 Answer

0 votes
by (30.6k points)

The UI Toolkit has a Timer control (question 2437) - use it when the toolkit is available. On toolkits without it, a timer coach view is ten lines:

// Coach view "Timer" - options: interval (Integer, ms), autoStart (Boolean); binding: Integer (ticks); boundary event on tick
// load handler
var me = this, handle = null;
me.start = function () { if (handle) return; handle = setInterval(function () {
    var n = (me.context.binding.get("value") || 0) + 1;
    me.context.binding.set("value", n);
    me.context.trigger(function () {}, { tick: n });          // fires the view's boundary event -> CSHS can call a service, refresh a table, etc.
  }, me.context.options.interval.get("value") || 5000); };
me.stop = function () { if (handle) clearInterval(handle); handle = null; };
if (me.context.options.autoStart.get("value")) me.start();
// unload handler: me.stop();

Typical uses: poll a service every N seconds (${Timer}'s boundary event > Stay on page > service flow > back to the coach), a countdown to the task due date (${Countdown}.setText(...)), auto-save drafts. Rules: always clear the interval in unload (otherwise the timer keeps running after the coach is gone), keep intervals ≥ 5 s for polling, and stop polling when the tab is hidden (document.hidden).

Alternatives: newer toolkits offer the Timer control with an on timeout event and start / stop methods; for server-side waiting inside a BPD use a timer intermediate event, not a coach timer (question 54).

References

Related questions

0 votes
1 answer 1.7k views
0 votes
1 answer 1.3k views
0 votes
1 answer 1.0k views
0 votes
1 answer 2.1k views
0 votes
2 answers 3.1k views
asked Oct 16, 2017 in Coach Views by qaziMateen (120 points)
0 votes
1 answer 1.7k views
0 votes
1 answer 1.9k views
0 votes
1 answer 2.0k views
0 votes
1 answer 4.0k views
0 votes
2 answers 1.8k views
0 votes
2 answers 2.9k views
0 votes
1 answer 2.4k views
0 votes
1 answer 1.8k views
0 votes
1 answer 2.5k 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
...