{
  "schemaVersion": 1,
  "snapshotDate": "2026-10-23",
  "slug": "reference-app-variables-core-variable-compareandset",
  "title": "Compare and set variable",
  "section": "Library asset reference",
  "description": "Write a declared workspace variable, validating its saved type before committing.",
  "kind": "node",
  "url": "/wiki/reference-app-variables-core-variable-compareandset/",
  "markdown": "/wiki/reference-app-variables-core-variable-compareandset/index.md",
  "json": "/wiki/reference-app-variables-core-variable-compareandset/index.json",
  "headings": [
    {
      "id": "catalog-identity",
      "title": "Catalog identity",
      "depth": 2
    },
    {
      "id": "inputs",
      "title": "Inputs",
      "depth": 2
    },
    {
      "id": "outputs",
      "title": "Outputs",
      "depth": 2
    },
    {
      "id": "configuration-schema",
      "title": "Configuration schema",
      "depth": 2
    },
    {
      "id": "source-and-installed-versions",
      "title": "Source and installed versions",
      "depth": 2
    }
  ],
  "sources": [
    "../OpenNodeFlow-Library/work/catalog-all.mjs",
    "../OpenNodeFlow-Library/work/azure-pack-consolidation-20261022/catalog-policy.mjs",
    "../OpenNodeFlow-Library/work/developer-packs-20261022/catalog.mjs",
    "shared/seed.ts",
    "shared/storage-library.ts",
    "shared/variable-library.ts",
    "shared/control-flow.ts",
    "shared/remote-routes.ts",
    "server/runtime-library.ts",
    "shared/error-library.ts",
    "shared/storage-model.ts",
    "shared/builtin-documentation.ts"
  ],
  "family": "app-variables",
  "contract": {
    "key": "app.variables.core.variable.compareAndSet",
    "slug": "app-variables-core-variable-compareandset",
    "name": "Compare and set variable",
    "kind": "node",
    "family": "app-variables",
    "packId": null,
    "category": "Variables",
    "description": "Write a declared workspace variable, validating its saved type before committing.",
    "inputs": [
      {
        "id": "exec",
        "name": "Exec",
        "type": "control",
        "typeName": "Control",
        "required": false
      },
      {
        "id": "value",
        "name": "Value",
        "type": "any",
        "typeName": "Any",
        "required": true
      },
      {
        "id": "expectedValue",
        "name": "Expected value",
        "type": "any",
        "typeName": "Any",
        "required": true
      },
      {
        "id": "expectedRevision",
        "name": "Expected revision",
        "type": "number",
        "typeName": "Number",
        "required": false
      }
    ],
    "outputs": [
      {
        "id": "next",
        "name": "Next",
        "type": "control",
        "typeName": "Control",
        "required": false
      },
      {
        "id": "value",
        "name": "Value",
        "type": "any",
        "typeName": "Any",
        "required": true
      },
      {
        "id": "revision",
        "name": "Revision",
        "type": "number",
        "typeName": "Number",
        "required": true
      }
    ],
    "configSchema": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120,
          "title": "Variable",
          "description": "Exact name in this workflow’s workspace. Choose an existing variable from the Variables menu."
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    },
    "documentation": "Choose a workspace variable in Configuration and explicitly bind it to save its exact ID and declared type/version on this node. Bound Value sockets use that exact type, without creating per-variable library definitions. Renaming a bound variable preserves its identity; deleting/recreating its name does not retarget this node. Existing unbound nodes keep their dynamic any sockets and name lookup until explicitly bound.\n\nCompare and set commits Value only when the current JSON equals Expected value (object key order is irrelevant). A mismatch fails without a write.\n\nAll writes validate the whole resulting value against the exact pinned type and commit once in a transaction. Optional Expected revision adds optimistic concurrency protection. Writes and their run Storage before/after journal commit immediately, even if later code fails. Never automatically repeat an uncertain mutation; inspect its value and revision first. Exec/Next establish control ordering. Missing variables fail; no operation creates one implicitly.\n\nRuntime helpers are context.variables.get/set/increment/append/compareAndSet/updatePath. The running workflow forces workspace scope. Name-only calls remain supported; an explicit binding enforces ID/workspace/type identity. Library tests use a fresh empty sandbox. Use Secrets/Connections for credentials.\n",
    "tags": [
      "builtin",
      "node"
    ],
    "source": "app-builtin-catalog"
  }
}
