There are at least two ways to work with collections of Structured Data Types (SDTs):
- Defining an SDT object as a collection and then defining a variable (in a certain object) based on that SDT.
- Defining an SDT object that is not a collection, and then defining a variable (in a certain object) based on that SDT and configuring the variable as a collection.
Note that although 'ClientsItem' is structured data representing each item of the collection, it does not exist as an independent SDT. The defined SDT is the collection one, 'Clients'.
After defining the Structured Data Type (SDT) object, you have to define a variable (in a certain object) based on the SDT collection (i.e. named &myClients) and another variable based on a single item of the SDT collection (i.e. named &eachClient):
Thus, you can, for example, iterate the collection as follows:
For &eachClient in &myClients
... //do something with &eachClient
EndFor
Note that the Collection property is set to 'False' for both variables in the above example.
In this case, the SDT structure has been defined exactly the same as the previous sample but the IsCollection checkbox has not been selected. This means that the SDT definition consists of one item, not a collection. So, how do you define a collection of this data type?
By defining the &myClients variable based on the SDT data type and indicating that it is a collection:
And defining the &eachClient variable based on the SDT:
The same code can be defined to iterate the collection:
For &eachClient in &myClients
... // do something with &eachClient
EndFor
The way to work with a collection will depend on the need to have defined the item itself. For example, if you need to return it from a Data Provider object because in the Output property of the Data Provider you cannot specify Clients.Client, a non-defined SDT. In that case, you will need to choose the second option.
That is, in the same Knowledge Base, 'Clients' SDT and 'Client' SDT, as they appeared before. Be careful, because GeneXus will not understand that 'Clients.Client' and 'Client' are the same.
Recursive SDTs
Structured Data Type editor
New operator (SDT)
Loading Compound Data Types (SDT) using Data Providers
Two ways of returning a collection using a Data Provider