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

IF <condition> THEN <code1> ENDIF

Executes code1 if condition is true

IF <condition> THEN <code1> ELSE <code2> ENDIF

Executes code1 if condition is true, otherwise executes code2

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

<list>.forEach(<element>: <code>)

Executes code for each element in the list.

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

calculate(<expression>, [<startDate>], [<endDate>])

Evaluates the expression for startDate, endDate for current context

<object>.calculate(<expression>, [<startDate>], [<endDate>])

Evaluates the expression for startDate, endDate for object context

<list>.calculate(<expression>)

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

this.start

Start date of the current context period

this.end

End date of the current context period

this.bop

Beginning of the current context period

this.bop.year

Year of the beginning of the current context period

this.bop.halfyear

Half year of the beginning of the current context period

this.bop.tertial

Tertial of the beginning of the current context period

this.bop.quarter

Quarter of the beginning of the current context period

this.bop.week

Week of the beginning of the current context period

this.bop.day

Day of the beginning of the current context period

this.eop

End of the current context period

this.eop.year

Year of the end of the current context period

this.eop.halfyear

Half year of the end of the current context period

this.eop.tertial

Tertial of the end of the current context period

this.eop.quarter

Quarter of the end of the current context period

this.eop.week

Week of the end of the current context period

this.eop.day

Day of the end of the current context period

this.period

Name of the current period type

this.dateRange

this.timePeriod

Name and year of the current period

this.timePeriod.start

Start time of the current period

this.timePeriod.end

End time of the current period

this.timePeriod.yearStart

this.timePeriod.yearEnd

this.timePeriod.number

The positional number of the period within the context year.

this.timePeriod.numberInYear

The positional number of the period within the calendar year. October -> 10

this.timePeriod.year

The calendar year of the context time period.