Official Content

Adds an item to a collection.

Syntax

&VarBasedOnSDTCollection.Add(&VarBasedOnSDTItem [ , Position ] )

Where:

&VarBasedOnSDTCollection
   It must be a variable based on an SDT collection (or a variable based on a simple SDT and defined as a collection).

&VarBasedOnSDTItem
    Variable based on the SDT item.

Position
    Relative position.

Scope

Generators: .NET, .NET Framework, Java, Ruby (up to GeneXus X Evolution 3).

Description

It adds an Item to the collection in a relative position: Position. If Position is omitted, or if “0” is specified, the Item is added at the end of the collection. Position starts at 1.

Before adding each element to a collection, it is necessary to create a memory space using the new operator.

Samples

Consider the following Structured Data Type (SDT) object:

Attractions SDT Is Collection

Suppose you define two variables in a Web Panel object (it could be another object), as shown below:

  • &Attractions: Based on the Attractions SDT (so, it is a collection of items with attractions data).
  • &OneAttraction: Based on Attractions.AttractionsItem (so, its data type corresponds to an item of the collection).

The &Attractions collection is already loaded with some items and you need to add a new item.

The following Event loads an item and adds it to the collection:

Event 'add attraction to the collection'
   &OneAttraction = new()
   &OneAttraction.Id = &Id       //a variable with value is assigned but it could be a fixed value or an attribute (if it is instantiated) 
   &OneAttraction.Name = &Name   //a variable with value is assigned but it could be a fixed value or an attribute (if it is instantiated)
   &Attractions.Add(&OneAttraction)
Endevent
Note: The same method can also be used to add a new item to a list of Java Scripts (in Transactions and Web Panels), as shown: Control.Add(Item). For more details, see: Access to a Web Object's Header

See Also

Structured Data Type methods

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