In ModelBuilder, you can substitute the value or dataset path of a variable by enclosing the variable name between percent signs (%Variable Name%). Substituting variables in this manner is called inline variable substitution. There are three categories of such variables
- Any variable existing in a model
- System variables that are added in the product such as %scratchGDB%, %scratchFolder%, %t% for time or %n% for iteration number
- Workspace Environments such as %scratchworkspace% or %workspace%
Examples of where inline variable substitution can be used includes:
- In an SQL query when the variable is exposed as a model parameter and the value is unknown until provided by the user.
- In any tool where there is no direct data type compatibility between an existing variable and a tool parameter. For example,
- In Calculate Field tool, when the value of the expression comes from a string variable which cannot be directly connected to the expression parameter.
- In Calculate Value tool where a variable data type can be casted to a different data type before passing it to another tool.
- In output path using system variables such as %scratchGDB% and %scratchFolder% that point to the project workspace.
- In output path using ModelBuilder workspace variables %scratchworkspace% and %workspace%, that point to the environment set in the model.
- In the output name if it needs a current time stamp %t% or an iteration number %n%.
To understand more, check out this video created by our summer intern, Atreyi Guin.
Additional resources:
Inline variable substitution help