community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx Designer Knowledge Base

Definitive answers from Designer experts.
Community v19.6

Looks aren't everything... But the latest Community refresh looks darn good!

Learn More

All About Constants

Alteryx
Alteryx
Created on

You're working on your gazillionth Formula tool and "Jeff" from Quality Assurance sends you an email 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 that one.. stupid.. little.. number.

 

You vow that you'll never again let smug "Jeff" ruin your night with his nitpicky tolerance standards, so you open up your browser, load up your home page (the Alteryx Community page duh), and find exactly what you've been looking for: a Knowledge Base article about document constants.

 

So what's a constant? According to the Alteryx Help pages: "Document Constants are global variables for a workflow. Constants make it possible to change a value in a single location and have that change propagate to the rest of the workflow."

 

You can find constants in your Workflow Properties tab (Click on the canvas and go to Workflow in the Configuration Window).

 

 

2018-11-14_15-43-31.png

The "Is Numeric" checkbox on the far right will make the value 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 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.

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

 

User

Clicking on the add.PNG 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 2018-11-14_15-51-08.png Annotation area of the Tool Properties.

 

2018-11-14_15-52-15.png

 

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.

 

2018-11-14_15-57-55.png

 

 

Engine and User constants will populate under the Constants menu in the Variables. They will come in as either numeric or string based on whether that Is Numeric checkbox is checked off.

Question constants will not show up in this menu, and cannot be typed in [...] notation like the other variables.

 

 

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.

 

2018-11-14_15-54-43.png

 

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 along data without even connecting up the Interface tool to the formula.

 

2018-11-14_16-04-58.png

 

Above we have a macro with the text box named "Constant", and below is the result when run in another workflow.

 

 

2018-11-14_16-00-03.png

 

Check out the attached example to see it all in action! (compiled in version 10.1)

 

Attachments
Comments
Meteor

Hello 🙂

 

How can I build it in order for this constant variable to be a date that the user types in? The idea is that the parameter will be used to query the database, for example, and then the same value will serve to add to the file we output.

Alteryx
Alteryx

Hi @Su!

 

If you would like to have the user type in the value for a constant in an app, you just need a Text Box tool like in the picture below.

 

original.png

 

You could name it anything you like instead of "Constant", and you would just refer to it in the form of "%Question.Constant%".

You could also possibly use the output of the Date tool instead, but this will always return the format "yyyy-mm-dd" which may not necessarily be what you need.

Asteroid

Can a constant be used in a SQL query or do you have to feed the constant via a control input for a macro with a data input node inside it?

@JMoore that's how I ended up in this thread also.  Wondering if it can be used in my SQL queries.

 

Asteroid

Any updates to whether we can use constants in SQL queries? It would make our workflows so much more robust.

Asteroid

To use a constant in a SQL is complicated I found but feed a constant into something (data input or formula) then run SQL query inside of dynamic input and adjust the query with a replace command, this is the general idea although I have yet to do it as I moved on from the issue.

Meteor
I seem to be able to call constants just fine in my SQL queries using the following syntax : '%Type.Name%'
Atom

Is there any way to use one constant to define another? Example: I have the constant User.ClientName, which equals "ABC Co."

I want to define another constant named User.FolderPath, using "C://Documents/%User.ClientName%/Reports". But when I try to set this up in this way, Alteryx errors out and says it can't find the folder with that path. 

 

Thoughts, anyone?