You are viewing the documentation for Blueriq 17. Documentation for other versions is available in our documentation directory.
TSL FOREACH IN statement
Use this statement to repeat a text for a subset of instances of an entity.
Syntax
[[[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:
Parent instance | Parent.Name | Child instance | Child.Name | Child.Date_of_birth |
---|---|---|---|---|
Parent_1 | John | Child_1 | Kim | 26-September-1998 |
Child_2 | Rick | 13-May-2000 | ||
Child_3 | Bob | 3-August-2003 | ||
Parent_2 | Dave | Child_4 | Mary | 4-June-1982 |
To create an overview of the children per parent you could create the following TSL message:
[[[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
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]]]