Skip to main content

Variable Referencing System

Overview​

The referencing system allows you to access outputs from various steps within your workflow. This system uses a simple syntax with the $ prefix to indicate a reference.

Basic Syntax​

All references in the system start with the $ symbol. This distinguishes them from regular strings or variables in your code.

Types of References​

Previous Step Reference​

  • Syntax: $prev
  • Usage: Refers to the default output of the immediately preceding step.
  • Example: print($prev) will print the default output of the previous step.

Specific Step Reference​

  • Syntax: $step[id].outputName
  • Usage: References a specific output from a specific step.
  • Example: $step["1"].result refers to the 'result' output of the step with ID 'step["1"]'.

Default Step Output Reference​

  • Syntax: $step[id]
  • Usage: Refers to the default output of the specified step.
  • Example: $step["2"] is equivalent to $step["2"].default.

Special References​

Loop Index​

  • Syntax: $loop.index
  • Usage: Provides the current index in a loop iteration.
  • Example: print($loop.index) inside a loop will print the current iteration number.

Loop Value​

  • Syntax: $loop.value
  • Usage: Represents the current value in a foreach loop.
  • Example: In a foreach loop over an array, $loop.value will give you the current element.

Best Practices​

  1. Always ensure that the step you're referencing exists and has been executed before your reference.
  2. Remember that $prev always refers to the immediately preceding step, which might change if you reorder your workflow.

Error Handling​

  • If you reference a step that doesn't exist or hasn't been executed yet, the system will raise an error.
  • Similarly, referencing an output that doesn't exist for a given step will result in an error.

Examples​

-- Printing the default output of the previous step
print($prev)

-- Using a specific output from a step
if $step["1"].isValid then
print("Step 1 is valid")
end

-- Using the loop index in a for loop
for i = 1 to 5 do
print("This is iteration " .. $loop.index)
end

-- Using loop value in a foreach loop
foreach item in items do
print("Current item: " .. $loop.value)
end

Remember, this referencing system is designed to make your workflows more dynamic and interconnected. Use it to create more powerful and flexible automations!