Environment
Read and write variables on the active environment. Runtime values include the merged inheritance chain for that environment; set and clear still persist only to the active leaf (local overrides), not to parent environments. When no environment is selected, hc.environment.name is an empty string and variable sets apply to the current send only (they are not persisted).
hc.environment.name
Available since v2.0.0
Signature:string (read-only)
Display name of the active environment. Empty string when no environment is selected.
console.log("Environment:", hc.environment.name);hc.environment.variables.clear(key)
Available since v2.0.0
Signature:(key: string) => void
Removes an environment variable by exact key, or every key under a namespace.* prefix (see namespaces). Matching keys are deleted from the active environment when the send completes (parent environments are unchanged).
hc.environment.variables.clear("token");
hc.environment.variables.set("workflow_a.token", "abc");
hc.environment.variables.clear("workflow_a.*");hc.environment.variables.get(key)
Available since v2.0.0
Signature:(key: string) => string | undefined
Returns the value set during this send (via hc.environment.variables.set) if present; otherwise returns the merged runtime variable value (global, collection, folder, and the active environment’s inheritance chain). Returns undefined if the key is not set.
var token = hc.environment.variables.get("token");hc.environment.variables.set(key, value)
Available since v2.0.0
Signature:(key: string, value: string) => void
Sets an environment variable for the remainder of this send and persists it to the active environment when the send completes (not to parent environments in an inheritance chain). Values are coerced to strings. New keys are added to the environment with an empty default and share: false. When no environment is active, the value applies to the send only.
hc.environment.variables.set("token", "abc123");
hc.environment.variables.set("timestamp", String(Date.now()));