Document toolboxDocument toolbox

This article is for Data Center. Visit Cloud

Expr Advanced Reference - Local Variables

Local variables are similar to Variables, but they are not mapped to an item's attribute or Jira field, but rather defined and calculated right in the expression.

The declaration syntax is the following:

Note the colon (":") that separates the expression assigned to the variable and the expression where the variable is used.

A few facts about local variables:

  • ExpressionWithLocalVariable may start with another local variable definition, so you can introduce many local variables in sequence. When defining a second variable, you can use the first variable already defined, and so on.
  • Local variables can "shadow" previously defined local and free (mapped) variables with the same name. If you write WITH priority = 10: <expression>, then when calculating <expression>, the value of priority will be 10, even if there was a variable attached to the issue's priority in the enclosing scope.
  • The WITH... construct is itself an expression, so you can use it, enclosed in parentheses, anywhere an expression can be used. The name defined in this expression is not visible outside the WITH... expression.

Immutability

Expr language constructs are immutable. Once a local variable is defined, it cannot change its value. (So, in fact, calling it a "variable" is not exactly correct. Although, if a local variable depends on external variables, which vary from item to item, the local variable itself will also vary from item to item.)

So if you're building your formula and you need to take a number of values through a series of calculations, you may need to use multiple local variables, going through each step and assigning each intermediate result to another local variable.