0 votes
909 views
by (21.5k points)

1 Answer

0 votes
ago by (30.6k points)

A formula is an expression entered in a control's Formula option (Text, Integer, Decimal, Output Text, Date, Checkbox... on the UI Toolkit) that computes the control's value from other controls; the toolkit re-evaluates it automatically whenever any control referenced in it changes. Syntax is plain JavaScript with control references:

// Decimal "Total" > Formula
${Qty}.getData() * ${Price}.getData()

// with a fallback and rounding
Math.round((${Qty}.getData() || 0) * (${Price}.getData() || 0) * 100) / 100

// text
${First}.getText() + " " + ${Last}.getText()

// inside a repeating table row: relative references
${../Qty}.getData() * ${../Price}.getData()

// across a list: sum of a column of the table "Lines"
${Lines}.getData().reduce(function (s, l) { return s + l.qty * l.price; }, 0)

// date
new Date(${Start}.getDate().getTime() + 14 * 86400000)

Rules: reference controls with ${controlId} (the framework tracks these references to know when to recompute); the expression must return a value of the control's type; do not put side effects in formulas (no setData on other controls - use events for that); a formula overrides the binding as the source of the value (the result is written to the bound variable, so the variable follows the formula); for table columns the formula runs per row.

When a formula is not enough (needs a service, async data, several outputs) use the control events (On change) and compute in JavaScript.

References

Related questions

0 votes
1 answer 1.3k views
0 votes
1 answer 849 views
0 votes
1 answer 1.5k views
0 votes
1 answer 895 views
0 votes
1 answer 1.8k views
0 votes
1 answer 787 views
0 votes
2 answers 3.1k views
+1 vote
2 answers 7.4k views
0 votes
1 answer 715 views
0 votes
1 answer 1.1k views
0 votes
1 answer 1.3k views
0 votes
1 answer 2.4k views
+1 vote
2 answers 6.6k 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
...