You are viewing the documentation for Blueriq 17. Documentation for other versions is available in our documentation directory.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

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

[[[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 instanceParent.NameChild instanceChild.NameChild.Date_of_birth
Parent_1JohnChild_1Kim26-September-1998


Child_2Rick13-May-2000


Child_3Bob3-August-2003
Parent_2DaveChild_4Mary4-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

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.

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]]]


Back to Top

  • No labels