Object MethodCore Flow

Workflow.set(name, value)

Updates a defined macro variable while preserving its type; returns true on success.

Documented for app version 1.0.64Updated:

Detailed Explanation

This section explains when to use the API, how to call it, and which structures it works best with in production flow.

How To Call It

Workflow is a global table: call its functions with a dot (Workflow.<method>(...)), not a colon. Requires Macro Handler 1.0.62 or later.

When To Use It

Updates a defined macro variable while preserving its type; returns true on success.

Parameters and Return

Define the variable in the Variables section of Macro Settings first. Supported types are text, integer, decimal, boolean, array, dictionary and color. Unknown names and type mismatches are errors. Each new run loads initial values. Legacy independent action plans retain their own variable definitions.

Best Combined With

Use Workflow.get/set in the Code editor or a Code block in No-Code or Logic. Arrays and dictionaries are copies; call set after editing them. Use KV for persistent values. Android action block fields take literal values; the Lua Automation.action args table also validates computed values.

Example Usage

The snippet below is a starter pattern that can be applied directly in runtime flow.

-- Define integer variable "count" in Macro Settings first.
local count = Workflow.get("count")
Workflow.set("count", count + 1)

Copyable Progressive Examples

From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.

Foundation

Shows the shortest direct way to call the API.

Foundation
-- Define integer variable "count" in Macro Settings first.
local count = Workflow.get("count")
Workflow.set("count", count + 1)

Simple

Wraps the base call with minimal flow control.

Simple
local stepOk = true
-- Define integer variable "count" in Macro Settings first.
local count = Workflow.get("count")
Workflow.set("count", count + 1)
if stepOk then
  wait(200)
end

Practical Flow

A practical pattern for real macros with pcall, logging, and guards.

Practical Flow
local ok, err = pcall(function()
  -- Define integer variable "count" in Macro Settings first.
  local count = Workflow.get("count")
  Workflow.set("count", count + 1)
end)

if not ok then
  print("API step failed: Workflow.set: " .. tostring(err))
  requestStop()
end

Detailed

This level packages the API into a reusable helper with error reporting.

Detailed
-- Workflow.set(name, value)
local function run_set_step()
  -- Define integer variable "count" in Macro Settings first.
  local count = Workflow.get("count")
  Workflow.set("count", count + 1)
end

local ok, err = pcall(run_set_step)
if not ok then
  toast("Step failed")
  print(err)
end

Combined

Combines the API with related structures to form a more realistic workflow.

Combined
-- Define integer variable "count" in Macro Settings first.
local count = Workflow.get("count")
Workflow.set("count", count + 1)