Variables

Variables let you save data during a Workflow run and reuse it in later Blocks. You might save a search term, read a product price from a page, or keep a count as a Loop runs.

If you are new to using variables in the editor, start with Use Variables. This guide explains how to create and update variables, where they are available, and how page elements affect their values.

What Is a Variable?

A variable is a named value. For example, a variable named searchTerm might hold the text wireless headphones. Later Blocks can refer to that name instead of repeating the text.

Each time a Block reads the variable, it uses the value available at that point in the run. If an earlier Block changes the value, later Blocks use the updated value.

Create a Variable

Use the Set Variables Block to create a variable. Give it a name, choose a data type, and select where its value comes from.

For a simple example, add a variable with these settings:

  • Name: searchTerm
  • Type: String
  • Data Source: Static
  • Default Value: wireless headphones

When this Block runs, it saves wireless headphones as searchTerm. With Static selected, the default value is the value the Block assigns.

Choose a Name

Choose a name that describes the data, such as productPrice, pageNumber, or isAvailable. Enter just the name in the Name field; Tapicker adds the $vars namespace when you insert a reference.

Names are case-sensitive: searchTerm and SearchTerm refer to different variables. Use letters, numbers, and underscores, and start with a letter or underscore to keep references easy to write. For example, productPrice can be read as {{$vars.productPrice}}.

Use a different name for each value you want to keep. Reusing a name updates the existing variable.

Choose a Data Type

Choose a type that matches the data you need:

  • String for text, such as a search term or URL.
  • Number for a price, quantity, or counter.
  • Boolean for a true or false value.
  • Array for a list of values, such as product links.
  • Object for related fields, such as a product's name and price.
  • Date for a date and time.

See Data Types for examples of each type.

Choose a Data Source

The data source determines how the Block gets the value:

  • Static uses the default value you enter.
  • Element reads data from a page element, such as its text or an attribute.
  • Dynamic uses an expression or template, which can reference existing variables.
  • Code runs JavaScript to produce a value. This option requires the Pro plan.

For sources other than Static, the default value provides a fallback when the source does not return a usable value. The result is converted to the selected data type after any configured data transformations.

For the full settings, see Set Variables.

Read a Variable

Variables are stored under $vars. To read searchTerm, use this expression:

{{$vars.searchTerm}}

In a later Input Text Block, enter that expression in a field that accepts variables. When the Block runs, it types wireless headphones into the target input.

You can also combine a variable with text:

Search results for {{$vars.searchTerm}}

Use the editor's suggestions to insert a reference without typing it yourself. Use Variables walks through the process; Template Syntax explains expressions, functions, and access to Array items and Object properties.

Update a Variable

To change a variable, add another Set Variables Block with the same variable name. Its new value replaces the previous value when that Block runs.

For example, to count completed items in a sequential Loop:

  1. Before the Loop, create a Number variable named completedCount, with Data Source set to Static and Default Value set to 0.
  2. Inside the Loop, after processing each item, add a Set Variables Block with the same name and type.
  3. Set its Data Source to Dynamic and enter {{ $vars.completedCount + 1 }}.

The count becomes 1 after the first item, 2 after the second, and so on. Keep this Loop sequential: concurrent iterations work with separate copies of the variables, so this pattern does not reliably count their combined progress.

Understand Variable Scope

A variable is available throughout the current Workflow run after the Block that sets it has executed. It is not limited to the Loop or branch where you created it.

Execution order still matters. A Block cannot use a value that a later Block has not set yet. If a branch containing Set Variables is skipped, that Block does not create or update its variables.

Each new run starts with an empty $vars namespace. Variables do not carry over from a previous run. If you need values that users can supply when starting a Workflow, use Set Arguments.

A Workflow called through Run Workflow also has its own variables. Pass the values it needs as arguments, and use Return to send a result back to the calling Workflow.

Work with Values from Page Elements

When a variable reads data from a page element, Tapicker keeps both the value and information about the source element in a Duck wrapper. This lets you reuse the extracted data or target the element it came from.

For example, if productTitle reads a product heading, use {{$vars.productTitle}} in a text field to insert its text. You can explicitly read the underlying value with {{$vars.productTitle.value}}.

In a Target Element field, a complete expression such as {{$vars.productTitle}} uses the Duck's saved target to locate the source element. See Use a Variable as the Target for examples, and Duck Values for details about the wrapper.