Skip to content

Global Variables

A global variable is a named value that you store once per tenant in the Workflow app. Custom Steps, Custom Event steps, routes and step settings read it at run time. Use global variables for thresholds, URLs, codes and small lookup tables that change more often than the logic: when the value changes, you edit the variable, not every script.

At a glance

  • Stored in The Workflow app, Global Variables. Every save creates a new version.
  • Read by GlobalVariables.Get("Name") in Custom Steps, Custom Event steps, Javascript routes and JavaScript preprocessors; by Expression and Global Variable routes; by the gear icon on step settings.
  • Written by People in the Workflow app, and code through V1_WorkflowAPI. Scripts cannot write them.
  • Returns Always a string. Parse it before you compare.
  • Best for A review limit, an approver list, a vendor table, an endpoint URL.

Where you set them

  1. Open the Workflow app, then Global Variables. You need the feature Configure Workflow Global Variables. To create, edit or delete a secret variable you also need Manage Secret Workflow Variables.
  2. Select Add a Global Variable.
  3. Enter the Global Variable Name. Names are case-sensitive.
  4. Under Global Variable Data Type, choose:
  5. Generic Value, then a data type: Boolean, Decimal, GUID, Integer, Javascript, JSON, Text, Text Array or Timespan.
  6. Activity Property, then an Activity (a step type) and a Property (a setting of that step). The variable then has the shape that setting needs.
  7. Select Secret only if the value is a credential or other sensitive text (see below). You cannot change this choice later.
  8. Add Tags if you want to filter the list later. Select OK, then set the value and save.

To change a variable, select it and use Actions:

  • Edit Variable Changes the value.
  • Variable Properties Changes the tags without touching the value.
  • Delete Removes the variable.

Users who have only View Workflows can see variable names (for example in the designer's suggestions), but not edit them.

How values are versioned

Every save creates a new version. A running work item reads the version that was current when the work item was last submitted to its workflow. In a sub-workflow, it reads the version that was current when it entered the sub-workflow. This rule is the same for every reader: Custom Steps, Custom Event steps, routes and step setting preprocessors.

So a change applies to work items that start after the change. Work items already in flight keep the old value.

How each extension point reads them

Where How
Custom Step GlobalVariables.Get("Name") returns the value as a string.
Custom Event step GlobalVariables.Get("Name"), same as above.
Javascript route GlobalVariables.Get("Name"), same as above.
Expression route Pick Global Variable as the value type of a condition.
Global Variable route The variable's value is the route's JavaScript condition.
Step setting Select the gear icon next to the setting's name, then Global Variable.
JavaScript preprocessor on a step setting GlobalVariables.Get("Name").
Liquid template Not available. The Liquid model holds only WorkItem.

Every value comes back as a string. Parse it before you compare: parseFloat(GlobalVariables.Get("ReviewLimit")). A missing variable throws Global variable {name} was not found. in every script.

Secret variables

A variable marked Secret hides its value in the Workflow app ("This value is secret and can't be displayed.") and in V1_WorkflowAPI/GetGlobalVariable.

  • Only users with Manage Secret Workflow Variables can create, edit or delete a secret variable. Without it, the app hides the secret option and shows "You cannot modify secret variables". A user who tries anyway is refused and signed out.
  • The secret flag is fixed when the variable is created. A secret variable cannot be made non-secret, and an existing variable cannot be made secret. To change it, create a new variable with a new name.
  • Workflow scripts can read a secret's value: Custom Steps, Custom Event steps, Javascript routes, Global Variable routes, Expression routes that compare to a global variable, and JavaScript and Global Variable preprocessors on step settings.

A script that reads a secret can expose it

Anything a script writes is visible to other people:

  • metadata in Monitor, Insight and the index panel;
  • events in your event store;
  • request bodies and headers in the systems you call;
  • error messages in Error.LastErrorMessage.

Use a secret only where it is needed, for example as the HTTP Headers setting of Call External API through the gear icon (an Activity Property variable for that setting). Never copy it into metadata, an event property or a thrown error. Review every script that calls GlobalVariables.Get on a secret name before you save the workflow.

Rules

  1. If the variable does not exist, GlobalVariables.Get throws Global variable {name} was not found. and the step or route fails, unless you catch the error.
  2. GlobalVariables.Get("Limit") || "10000" does not fall back: the call throws before || runs. Use the helper below.
  3. Keep credentials where the receiving system expects them, such as a function's app settings. If a workflow must send a credential, store it as a secret variable and pass it only through a step setting.
  4. Test a new value with a new work item. Work items in flight keep their version.

To fall back to a default when a variable is missing:

getVariable helper (Custom Step, Custom Event, routes)
function getVariable(name, fallback) {
  try {
    var value = GlobalVariables.Get(name);
    return (value === null || value === undefined || value === "") ? fallback : value;
  } catch (e) {
    return fallback;
  }
}

var limit = parseFloat(getVariable("ReviewLimit", "10000"));

Set and read them through the API

The public API has four actions in the V1_WorkflowAPI group.

  • Request Every action is POST https://{tenant}/api/V1_WorkflowAPI/{Action} with a JSON body.
  • Feature The token needs the feature Manage Workflows.
  • Secrets The actions that touch a secret variable also need Manage Secret Global Variables.
  • Auth For authentication and the response envelope, see Authentication.

SetGlobalVariable

Creates or updates a non-secret variable. Each call saves a new version and keeps the variable's group.

SetGlobalVariable request body
{
  "Name": "ReviewLimit",
  "Value": "15000",
  "Tags": ["Finance"],
  "Type": "Decimal",
  "SubType": "Decimal"
}
  • Type Type is the stored data type name, for example String, Decimal, Int32, Boolean or JSON. Use the type the variable already has.
  • Returns The variable you sent.
  • Fails On a secret variable with You cannot degrade or upgrade a global variable's secret property after creation!

SetSecretGlobalVariable

Creates or updates a secret variable. Same body as SetGlobalVariable. Needs Manage Secret Global Variables as well as Manage Workflows.

  • Fails On an existing non-secret variable with the same "degrade or upgrade" message. The secret flag cannot change.
  • No permission Fails without the secret feature with You cannot modify secret property on this global variable because you do not have the relevant permissions.

GetGlobalVariable

Returns a non-secret variable with its value and metadata.

GetGlobalVariable request body
{ "Name": "ReviewLimit" }
  • Fails: on a secret variable with Cannot view global variable as it is marked as secret. To see the secret's global variable's tags and type, please use GetGlobalVariableMetadata.

GetGlobalVariableMetadata

Returns { "Name", "Tags", "Type", "IsSecret" } without the value. Same body as GetGlobalVariable.

  • Secrets Works on a secret variable only when the token also has Manage Secret Global Variables.
  • Not found A variable that does not exist returns Success: true with Data: null. Check Data, not only Success.

Gotchas

Mistakes that bite

  • The new value has no effect. Work items already in flight read the version from their submit time. Test with a new work item.
  • Global variable reviewLimit was not found. The name is case-sensitive. Copy it from the Global Variables list.
  • The fallback never applies. A missing variable throws before || runs. Use the try/catch helper above.
  • A secret value shows up in Monitor. A script copied it into metadata. Remove the write, then rotate the secret: anyone who opened the work item may have seen it.
  • "You cannot modify secret variables". Your user lacks Manage Secret Workflow Variables. Ask an administrator.
  • You need to un-secret a variable. You cannot. Create a non-secret variable with a new name and update the scripts that read it.