Page History
Panel | ||||
---|---|---|---|---|
TSL IF statement [[[IF expr]]] [[[/IF]]]The IF statement enables you to selectively perform tasks within your TSL message, based on some criteria which evaluate to TRUE or FALSE. Syntax
Inputs
Example Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
When user John Doe logged on, the message shown in your application is: “Welcome Mr. John Doe” When user Jane Doe logged on, the message shown in your application is: “Welcome Mrs. Jane Doe” If the gender is unknown the message will look like this: “Welcome Jane Doe” | ||||
Panel |
Code Block |
---|
[[[IF expr]]] message1 [[[ELSE]]] message2 [[[/IF]]] |
Inputs
- expr: is an expression that evaluates to TRUE or FALSE
message1 and message2: are TSL messages, so they can contain plain text and other TSL conditions
Example
Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
Code Block |
---|
Welcome [[[IF user.gender = 'male']]]Mr.[[[ELSE]]] Mrs.[[[/IF]]] [[[user.first_name]]] [[[user.last_name]]] |
When user John Doe logged on, the message shown in your application is: “Welcome Mr. John Doe”
If the gender is unknown the message will look like this: “Welcome Jane Doe”
TSL IF ELSEIF statement [[[IF expr1]]] [[[ELSEIF expr2]]] [[[/IF]]]
The IF ELSEIF statement enables you to selectively perform tasks within your TSL message, based on some criteria, which evaluate to TRUE or FALSE.
When TRUE executes the task specified in the IF part of the statement, the task specified in the ELSEIF part of the statement is only executed when the specified criteria are met.
Syntax
Code Block |
---|
[[[IF expr1]]] message1 [[[ELSEIF expr2]]] message2 [[[/IF]]] |
Inputs
expr1 and expr2: are expressions which evaluate to TRUE or FALSE
message1 and message2: are TSL messages, so they can contain plain text and other TSL conditions.
Example
Suppose you want to create a welcoming message after a user has logged in to your application. Then you could create the following TSL message:
Code Block |
---|
[[[IF time.hour >= 0 AND time.hour < 6]]]Good night [[[ELSEIF time.hour >= 6 AND time.hour < 12]]]Good morning [[[ELSEIF time.hour >= 12 AND time.hour < 18]]]Good afternoon [[[ELSEIF time.hour >= 18 AND time.hour ⇐ 23]]]Good evening[[[/IF]]] [[[user.first_name]]] [[[user.last_name]]] |
When user John Doe logged on at 8 o’clock am, the message shown in your application is: “Good morning John Doe”
When user John Doe logged on at 7 o’clock pm, the message shown in your application is: “Good evening John Doe”
UI Text Box | ||
---|---|---|
| ||
make sure the entire time.hour range is covered, otherwise the message would simply say “John Doe” |
TSL FOREACH statement [[[FOREACH entity]]] [[[/FOREACH]]]
Use this statement to repeat a text for each instance of an entity.
Syntax
Code Block |
---|
[[[FOREACH entity]]] message [[[/FOREACH]]] |
Inputs
entity: is an entity name
message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you want to create an overview of all registered users. Then you could create the following message:
Code Block |
---|
[[[FOREACH user]]]Name: [[[user.last_name]]], [[[user.first_name]]][[[/FOREACH]]] |
If you have three registered users: John Doe, Jane Doe and Mr X your user list would look like this: Name: Doe, John Name: Doe, Jane Name: X, Mr
TSL FOREACH IN statement [[[FOREACH entity IN relation]]] [[[/FOREACH]]]
Use this statement to repeat a text for a subset of instances of an entity.
Syntax
Code Block |
---|
[[[FOREACH entity IN relation]]] message [[[/FOREACH]]] |
Inputs
entity: is the child entity
relation: is the relationship between the parent and the child entity
message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you created a parent and a child entity. The parent has a multivalue relation with the child via the attribute Parent.Has_Children.
If the following instances where created:
To create an overview of the children per parent you could create the following TSL message:
Code Block |
---|
[[[FOREACH Parent]]] [[[Parent.Name]]] has children: [[[FOREACH Child IN Parent.Has_children]]] Name: [[[Child.Name]]] Date of birth: [[[Child.Date_of_birth]]], [[[/FOREACH]]] [[[/FOREACH]]] |
This results in:
John has children: Name: Kim Date of birth: 26-09-1998, Name: Rick Date of birth: 13-05-2000, Name: Bob Date of birth: 03-08-2003 Dave has children: Name: Mary Date of birth: 04-06-1982
UI Text Box | ||
---|---|---|
| ||
If we leave out the outer iteration [[[FOREACH Parent]]] the system would use the ‘current-instance’ of the Parent entity. In this case we are responsible for selecting an instance of the Parent entity before using this message. |
UI Text Box | ||
---|---|---|
| ||
You can combine the IN, WHERE and ORDER BY if you wish. Example: Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]] |
TSL FOREACH WHERE statement [[[FOREACH entity WHERE condition]]] [[[/FOREACH]]]
Use this statement to repeat a text for a subset of instances of an entity.
Syntax
Code Block |
---|
[[[FOREACH entity WHERE condition]]] message [[[/FOREACH]]] |
Inputs
entity: is the child entity
condition: the condition that must hold for an instance
message: is a TSL message, so it can contain plain text and other TSL conditions
Example
Suppose you have multiple persons. If the following instances where created:
To create an overview of all persons older than 40 you could create the following TSL message:
Code Block |
---|
Persons older than 40: [[[FOREACH Person WHERE Person.Age>40]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]] |
This results in:
Persons older than 40: Angela, 47; Dave, 82;
UI Text Box | ||
---|---|---|
| ||
You can combine the IN, WHERE and ORDER BY if you wish. Example: Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]] |
TSL FOREACH ORDER BY statement [[[FOREACH entity ORDER BY attr DESC|ASC]]] [[[/FOREACH]]]
When you use the FOREACH or FOREACH IN statement to repeat a text for multiple instances, you can add the ORDER BY statement to create an ordered list of texts. Add either DESC if you want to sort the list descending or ASC if you want to order the list ascending.
Syntax
Code Block |
---|
[[[FOREACH entity ORDER BY attr DESC|ASC]]] message [[[/FOREACH]]]
[[[FOREACH entity IN relation ORDER BY attr DESC|ASC]]] message [[[/FOREACH]]] |
Inputs
- entity: is the child entity
attr: the attribute by which the list of instances will be ordered. DESC stands for descending order. ASC stands for ascending sort order
- message: is a TSL message, so it can contain plain text and other TSL conditions
- relation: is the relationship between the parent and the child entity
UI Text Box | ||
---|---|---|
| ||
You can combine the IN, WHERE and ORDER BY if you wish. Example: Persons older than 40: [[[FOREACH Person IN TestEntity.rel WHERE Person.Age>10 ORDER BY Person.Age Asc]]] [[[Person.Name]]], [[[Person.Age]]]; [[[/FOREACH]]] |
TSL sequence [[[#]]]
Use this operator to add a sequence-number to each instance in a set of instances.
Note: The sequence operator returns the sequence-number of the FOREACH loop that it is used in. It is not the sequence in which the instances where created. The sequence number starts at 0.
Syntax
Code Block |
---|
[[[#]]] |
Input
- # is the sequence operator
Example
Suppose you want to create an overview of all registered users. Then you could create the following message:
Code Block |
---|
[[[FOREACH user]]][[[# user.last_name]]], [[[user.first_name]]][[[/FOREACH]]] |
If you have three registered users: John Doe, Jane Doe and Mr X your user list would look like this: 0 Doe, John 1 Doe, Jane 2 X, Mr
Or you want to create a comma separated list that contains all users:
Code Block |
---|
[[[FOREACH user]]] [[[user.first_name]]] [[[user.last_name]]]
[[[IF # != (COUNT user.last_name - 1)]]], [[[ELSE]]]. [[[/IF]]]
[[[/FOREACH]]] /*end user loop*/ |
Than the result would look like this:
John Doe, Jane Doe, Mr X.
TSL formats [[[expression{format}]]]
There are two different types of formatting available in TSL, number formats and date formats. Both formats are applied to attributes or expressions in the same way.
Syntax
Code Block |
---|
[[[expression{format}]]] |
Inputs
expression: is a number or date
format: is the number or date formatting
Numbers
In TSL, you can use number formats to change the appearance of numbers, without changing the number behind the appearance. The number format you apply does not affect the actual value. In this context a number can be any of the following basetypes; number, integer, currency or percentage.
The number formats used in TSL are common Java decimal formats. The most commonly used formatting symbols are listed below. For a complete documentation we refer to the online java documentation that is available at https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/DecimalFormat.html.
These symbols are used to create a format pattern. How this pattern is created is shown in the examples below.
To use the symbols as ordinary characters in your expression use the escape character.
UI Text Box |
---|
Note that the formatting depends on the language that is used. This means that when you specify a thousand separator |
Examples
Dates
In TSL, you can use date formats to change the appearance of dates, without changing the date behind the appearance. The date format you apply does not affect the actual value.
These symbols are used to create a format pattern.
Examples
NOW{hh:mm a}