Skip to main content

Constants

Constants are global variables for a workflow. They are defined on the Workflow tab in the Workflow Configuration window. Use constants to change a value in a single location and have that change apply to the rest of the workflow.

There are 3 types of constants:

  1. Engine: Five Engine constants display in every workflow and an additional constant, IterationNumber, displays when the Workflow Type is a Batch, Iterative, or Location Optimizer macro.

    • TempFilePath: The directory where the engine writes temporary files.

    • Version: The version number of the Alteryx Engine installed on the machine.

    • WorkflowDirectory: The directory of the current workflow. If no workflow is open, the value is the Alteryx installation directory.

    • WorkflowFileName: The file name of the workflow, which is only available if the workflow has been saved.

    • GuiInteraction: A Boolean value that indicates whether or not a workflow is being run from the GUI.

      • When a workflow is run from the Alteryx Designer or Analytic App interface, the returned value is True, or 1.

      • When a workflow is run from the command line, the returned value is False, or 0.

    • IterationNumber: An integer that corresponds to the number of times a macro has run, starting at 0.

  2. Question: When the Workflow Type is Analytic App or Macro, many of the Interface tools display as Question constants. The name of the constant corresponds to the name of the tool (Name field on the Annotation tab of the tool's configuration window). Go to Interface Tools for more information.

    • __cloud:UserId: This constant is intended for use specifically with the Text Box Interface tool. Use this constant to capture the user ID of the user running a workflow or app at runtime. To use this constant, you must enter __cloud:UserId (note the 2 underscore characters) into the Text Box tool's Name field (Annotation tab of the tool configuration). Combine this with the Hide control (for API development) configuration setting to prevent the app user from interacting with the constant.

  3. User: You can create and edit user constants via the Workflow Configuration window.

Add a User Constant

In the Workflow tab of the Workflow - Configuration window...

  1. In the Constants section, select the add (+) button.

  2. Enter a Name and Value.

  3. If the value is a number, select the checkbox in the # column. By default, constants are strings.

Delete a Constant

  1. Highlight the constant.

  2. Select the delete (-) button.

Use a Constant

There are a couple of ways to use a constant.

Use a Constant in an Expression

Engine and user constants display as variables that you can use to build an expression in any tool that uses an expression editor.

use-constant.png

The data type for a constant is determined by whether it is designated as a number or a string on the Workflow tab in the Workflow - Configuration window.

Note that question constants are not displayed in the expression editor. Go to Expression Editor for more information.

Use a Constant via a Reference Shortcut

You can use a reference shortcut to use any constant in the configuration of a tool. To specify a constant variable, add a % (percent sign) at the beginning and end of the name: %ConstantType.ConstantName%.

The reference shortcut can then be used in an expression editor or in a text box, and the constant can be updated via a Question tool or modified on the Workflow tab in the Workflow - Configuration window.

Be cautious when you use this method, as it might not always produce the expected results.