Welcome to the Alteryx Knowledge Base
Created/Edited -
You're working on yet another Formula tool and a colleague from Quality Assurance sends you an email stating that the margin of error for your process has been restandardized. It's not 0.122 anymore but 0.121. Then the horrible reality sets in - you're going to have to go back through all of your formulas and update them...
To help you work faster and smarter in the future, use constants!
What is a constant? According to the Alteryx Documentation: "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".
The "Is Numeric" checkbox on the far right converts the value to numeric rather than a string.
Types of Constants
Engine
Those four Engine constants will show up in every workflow, and an additional constant, IterationNumber, pops in there when you are authoring a Batch, Iterative, or Location Optimizer macro.
Temp File Path: The directory where the engine will write temporary files.
Version: The version number of the Alteryx engine installed on the machine.
Workflow Directory: The directory of the current workflow. If no workflow is open, the value will be the Alteryx installation directory.
GuiInteraction: A Boolean value indicating 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 will be True or 1. When a workflow is run from command line, the returned value is false, or 0.
Iteration Number: An integer that corresponds to the number of times a macro has run, starting at 0.
User
Clicking on the symbol will allow you to add User Constants. In the above screenshot, I added a "Favorite Number" User Constant. These can be strings or numerics, and will stick with the workflow if you send it, schedule it, or upload it to a Gallery.
Question
If you're making an app or macro, many of your Interface Tools will show up as Question Constants. The name of this constant will correspond to the name of the tool in the Annotation area of the Tool Properties.
How to use constants
Formula Method
You can bring in a constant in any tool with a Formula Processor component, such as in the Formula, Filter, and Dynamic Rename tools.
Engine and User constants appear in the Constants section of the Variables menu in tools like the Formula tool. Their data type (string or numeric) depends on whether the Is Numeric option is selected.
Question constants do not appear in the Variables menu. However, they can still be referenced manually by typing their name using standard bracket notation (for example, [ConstantName]), provided the name matches the Interface tool annotation.
Alternatively, Question constants can be referenced using the %Question.ConstantName% shortcut in the tool configuration fields.
Reference Shortcut
Any constant (Question included) can be called upon in any configuration option using a reference shortcut. This may not always work exactly like you think it will, so use this method with caution.
Generally, in any configuration you can type into, you can bring in a constant by using the notation %Type.ConstantName%. For example, in our Formula tool, we could refer to that Question constant in our Expression Editor.
Note: we still had to place it within quotes, because these do not come in with our constant value.
Using the reference shortcut, we can pass data along without even connecting the Interface tool to the formula.
Above we have a macro with the text box named "Constant", and below is the result when run in another workflow.
Check out the attached example to see it all in action!