Template Functions
Introduction
Templates can do more than just inserting values. With functions you can manipulate data, compare data and even work with sets (arrays) of data. It basically turns the template into a small script.
We try to keep the features similar to the smart values available in Automation for Jira. For technical reasons we have to use a different syntax but with very similar results.
Functions can be used as inline function or as a block function.
Inline functions are visible on the template, so the result will be shown to the user
Block functions are only structure and invisible to the user. It is up to you to use the result of the function and displays it to the user.
<!-- inline function - Replaces the element with the function's result-->
<!-- Syntax -->
{{functionCommand argument1 ...}}
<!-- Example -->
Deadline: {{addDay issue.duedate 5}} <!-- Deadline: 2022-30-12 -->
<!-- block function - will be ignored in the template-->
{{#functionCommand argument1 ...}}
<!-- Use the block function's result here to show data -->
{{/functionCommand}}
Most-used Functions
if/else
Block function that allows you to show parts of the template conditionally.
{{else}}
may be used within the if
-Block.
It is a basic function and only checks for a boolean value(true/false), so it is most useful with other functions (eq, isEmpty) below.
Parameters
{{#if value}}...{{/if}}
value
boolean. If true, it will show the content.
Examples
{{#if (isEmpty issue.attachment)}}
This issue has no attachments.
{{else}}
This issue has attachments.
{{/if}}
Detailed information
unless
Block function that is the reverse of the if
function. The block of the unless function will be rendered if the expression returns a falsy value.
Parameters
{{#unless value}}...{{/unless}}
value
boolean. If false, it will show the content.
Examples
{{#unless issue.description}}
This issue has no description.
{{/unless}}
Detailed information
eq
Similar to if
, but allows to compare 2 values and allows easy conditions based on values. Oftentimes you would compare a dynamic value (e.g. from the issue) with a static value, but you can also compare 2 dynamic fields.
Comparing arrays and objects is not supported.
{{else}}
may be used within the eq
-Block.
Parameters
{{#eq a b}}...{{/eq}} OR {{eq a b}}
a
can be any valueb
value to compare if it is equals witha
Examples
Detailed information
exists
Checks if a value exists. Helpful to avoid undefined
or null
values within the template .
Parameters
{{exists value}}
value
any value to check if it exists
Examples
each
Iterating on a list of values.
Parameters
{{#each array}}...{{/each}}
array
an array of values, e.g. comments
Examples
Detailed information
setVariable
Allows you to define own variables and access their value later on. Variables set this way are immutable, meaning they can only be set once and cannot be overridden afterwards.
Parameters
{{setVariable varName value}}
varName
stringvalue
any
Examples
Additional functions
There are a lot more functions available to discover. We use a set of helpers for very specific needs.
Please check the documentation for each category:
DateTime conversion functions
format
Lets you format an ISO-Date to a presentable format. By default it will be converted automatically to the user’s time zone based on their Atlassian settings.
Parameters
{{format isoDate formatKey locale}}
isoDate
string, can be the result of another function or an Atlassian date or datetime fieldformatKey
string (optional), defaults todateShort
locale
string (optional), defaults to the current Atlassian user locale
Examples
See table below for all formatKeys
timezone
Converts an ISO-Date to a specific time zone.
The output will be a full ISO-Date converted to the specified time zone.
Parameters
{{timezone isoDate zone}}
isoDate
stringzone
string
Examples
DateTime math functions
add[Second, Minute, Hour, Day, Week, Month, Year]
Allows you to modify an ISO-Date by increasing it a certain amount of a unit.
The output will be a full ISO-Date converted to the user’s time zone based on their Atlassian settings.
Parameters
{{add<Unit> isoDate amount}}
isoDate
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.amount
number
Examples
subtract[Second, Minute, Hour, Day, Week, Month, Year]
Allows you to modify an ISO-Date by decreasing it a certain amount of a unit.
The output will be a full ISO-Date converted to the user’s time zone based on their Atlassian settings.
Parameters
{{subtract<Unit> isoDate amount}}
isoDate
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.amount
number
Examples
DateTime compare functions
When comparing two ISO-Dates the unit specifies the granularity of the comparison and not which part of the date will be compared.
E.g. when comparing by month 2022-10 will never be equal to 2021-10 as the entire date is considered, so 2022-10 is a greater value than 2021-10.
All comparisons will be done with both dates having their time zone normalized and will return a boolean value.
isBefore[Second, Minute, Hour, Day, Week, Month, Year]
Checks if a ISO-Date is before another ISO-Date. isoDate1 < isoDate2
Parameters
{{isBefore<Unit> isoDate1 isoDate2}}
isoDate1
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.isoDate2
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.
Examples
isBeforeOrSame[Second, Minute, Hour, Day, Week, Month, Year]
Checks if a ISO-Date is before or equal to another ISO-Date. isoDate1 <= isoDate2
Parameters
{{isBeforeOrSame<Unit> isoDate1 isoDate2}}
isoDate1
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.isoDate2
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.
Examples
isSame[Second, Minute, Hour, Day, Week, Month, Year]
Checks if a ISO-Date is equal to another ISO-Date. isoDate1 == isoDate2
Parameters
{{isSame<Unit> isoDate1 isoDate2}}
isoDate1
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.isoDate2
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.
Examples
isAfterOrSame[Second, Minute, Hour, Day, Week, Month, Year]
Checks if a ISO-Date is after or equal to another ISO-Date. isoDate1 >= isoDate2
Parameters
{{isAfterOrSame<Unit> isoDate1 isoDate2}}
isoDate1
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.isoDate2
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.
Examples
isAfter[Second, Minute, Hour, Day, Week, Month, Year]
Checks if a ISO-Date is after or equal to another ISO-Date. isoDate1 > isoDate2
Parameters
{{isAfter<Unit> isoDate1 isoDate2}}
isoDate1
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.isoDate2
string, If only a date and no time is provided like2015-11-15
it will be converted internally to2015-11-15T00:00:00.000
. If only a time and no date is provided it will assume today as the date. So on 15 November 202213:01
will be converted to2015-11-15T13:01.00.000
.
Examples
Known Limitations
sum
function is currently not working. Please use theadd
function instead.