Official Content

There are at least two ways to work with collections of Structured Data Types (SDTs):

  1. Defining an SDT object as a collection and then defining a variable (in a certain object) based on that SDT.
  2. 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.

Samples

1. Defining an SDT as a collection

ClientsSDTCollection

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):

VariableSDTMyClientsProperties VariableSDTEachClientProperties

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.

2. Define an SDT that is not a collection

ClientSDTNotCollection

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:

VariableSDTMyClientsCollection 

And defining the &eachClient variable based on the SDT: 

VariableSDTEachClientProperties2

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.

What if you define both SDTs?

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.

See also

Recursive SDTs
Structured Data Type editor
New operator (SDT)

Videos

Start Video Loading Compound Data Types (SDT) using Data Providers
Start Video Two ways of returning a collection using a Data Provider



Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant