Table of contents
Official Content
  • This documentation is valid for:

The Variable Component allows you to define Velocity Templates (VTL) to include logic for variable assignment. This feature enhances the flexibility and power of variable manipulation in your Flows.

For detailed information on VTL syntax and usage, refer to the Velocity User Guide.

Advanced usage scenarios for the Variable Component are shown below, demonstrating how to leverage VTL for common tasks such as concatenating array values and incrementing counters.

Concatenating Values from an Array

To transform an array of values from an API response and send those values to an Assistant in another variable, you can create a new variable using a VTL script. This script generates plain text content to send to the Assistant.

Sample

Suppose you have a variable {items} mapped from an API response with the following content:


  {
    "name": "John",
    "age": 23
  },
  {
    "name": "Jane",
    "age": 23
  }

To create a new variable {userNames} containing a comma-separated list of names, use the following VTL script:

#foreach( $item in {items} )
    $item.name#if( $foreach.hasNext ), #end
#end

This script will assign the following value to {userNames}:

John, Jane

Incrementing a Counter

To increment the value of a Number variable, use the following script:

#set( {count} = {count} + 1)
{count}

To cast a String value to an Integer, use this script:

#set( {count} = $number.toNumber({count}) + 1)
{count}

Note: The first line of the script increments the variable by 1, and the second line reassigns the value to the variable. This second line is necessary due to the nature of the variable component editor, which works as a template editor.

Last update: March 2025 | © GeneXus. All rights reserved. GeneXus Powered by Globant