Control Flow
Extended supports several different control flow statements. These can be used to write conditional statements, as well as to iterate through lists.
Statements
Statement |
Definition |
IF-THEN-ELSE |
Conditional statement |
forEach |
Looping statement |
calculate |
Context applying statement (can also be used for looping). |
IF-THEN-ELSE
The IF-THEN
statement can be used to execute code if a condition is met. When the optional ELSE
is added,
it turns into the IF-THEN-ELSE
statement. The IF-THEN-ELSE
statement will execute a separate piece of code if
the first condition is not met. IF
statements can be nested inside one another.
Syntax |
Result |
|
Executes |
|
Executes |
Examples
IF t.CORPORATE_KPI001.actual > t.CORPORATE_KPI002.actual THEN // Checks if KPI1's value is greater than KPI2's
largestKpi := t.CORPORATE_KPI001 // If KPI1 is larger, assignts it to variable largestKpi
ELSE
largestKpi := t.CORPORATE_KPI002 // Otherwise assigns KPI2 to variable largestKpi
ENDIF
forEach [ 5.0.11.0 +]
The forEach()
method can be used to iterate through the elements inside of a list. This can be handy when trying to
work with many objects, or when trying to build a table using many addRow()
.
Syntax |
Result |
|
Executes |
- element
A variable containing the current element of the list. Everytime it loops, this variable is updated with the next element in the list.
Examples
myTable := createtable("ID", "Name", "Responsible") // Create a table with 3 columns
myKpis := list(t.CORPORATE_KPI001, t.CORPORATE_KPI002) // Create a list containing 2 KPIs
myKpis.forEach(currentKpi: // Iterate through list, using "currentKpi" as variable name
myTable.addRow(currentKpi, id, name, responsible) // Add a row with the KPI currently being iterated over to table
)
myTable // Return the table
calculate
calculate()
is a powerful function that is used to apply specific context to an expression.
It can be used for calculating an expression for a particular object and time period, as well as iterating over and manipulating a list of objects.
If chained to an object or object variable,
calculate()
will use that object as the context for the expression. Otherwise, it will use the currently selected context.If chained to a list,
calculate()
will iterate through each item in the list and apply the expression to that item and its context.A special keyword
self
can be used to refer to the item currently being iterated over.
Syntax |
Result |
|
Evaluates the expression for |
|
Evaluates the expression for |
|
Returns a list containing the result of evaluating the expression for each object in the list |
- expression
The expression that should be evaluated with the given context.
- startDate
[Optional] The start date of the period context for which the expression should be evaluated.
- endDate
[Optional] The end date of the period context for which the expression should be evaluated.
- object
The object context that should be used for evaluating the expression.
- list
The list of items for which the expression should be evaluated on each item.
Examples
calculate(actual, BOY, EOP) // calculates the actual YTD value of the currently selected context object
t.IND_001.calculate(target) // calculates the target for object with ID "IND_001" for the current time context
t.IND_001.calculate(target, BOP - 1Y, EOP - 1Y) // calculates the target for the object with ID "IND_001" for 1 year ago from the current time context
myKpis := LIST(t.KPI001, t.KPI002, t.KPI003)
responsibleUsers := myKpis.calculate(responsible) // returns a list of the responsible property value for each KPI in the list
responsibleUsers // the list of responsible Users
myNodes := myKpis.calculate(
curKpi := self // assigns the individual Kpi currently being looped over to a variable
curID := curKpi.id // assigns the id of the Kpi to a variable
nds := SELECT Node WHERE id = curID // queries for nodes that have the same ID
nd := nds.first() // takes the first item of the nodes list (nodes list shoud either have 1 item or be empty)
// and assigns it to a variable
nd // yields the node variable as the value for the expression
)
myNodes // A list of nodes with IDs that match the IDs of the KPIs in the myKpis list
Time Context Tokens
Extended has many token expressions that correspond to the context time.
Expression |
Result |
|
Start date of the current context period |
|
End date of the current context period |
|
Beginning of the current context period |
|
Year of the beginning of the current context period |
|
Half year of the beginning of the current context period |
|
Tertial of the beginning of the current context period |
|
Quarter of the beginning of the current context period |
|
Week of the beginning of the current context period |
|
Day of the beginning of the current context period |
|
End of the current context period |
|
Year of the end of the current context period |
|
Half year of the end of the current context period |
|
Tertial of the end of the current context period |
|
Quarter of the end of the current context period |
|
Week of the end of the current context period |
|
Day of the end of the current context period |
|
Name of the current period type |
|
|
|
Name and year of the current period |
|
Start time of the current period |
|
End time of the current period |
|
|
|
|
|
The positional number of the period within the context year. |
|
The positional number of the period within the calendar year. October -> 10 |
|
The calendar year of the context time period. |