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: docs.
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: docs
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
{{eq 1 2}} <-- prints false -->
{{#eq issue.priority.name "high"}}
Issue with high priority
{{else}}
Issue is not important
{{/eq}}
Detailed information: docs
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
<!-- Only prints Assignee if set -->
{{#if (exists issue.assignee)}}
Assignee: {{issue.assignee.displayName}}
{{/if}}
<!-- Some edge cases -->
{{exists "0"}} <!-- results in false -->
{{exists "null"}} <!-- results in false -->
{{exists "undefined"}} <!-- results in true -->
{{exists undefined}} <!-- results in false -->
{{exists "true"}} <!-- results in true -->
{{exists "false"}} <!-- results in false -->
{{exists []}} <!-- results in true -->
{{exists ""}} <!-- results in false -->
each
Iterating on a list of values.
Parameters
{{#each array}}...{{/each}}
array
an array of values, e.g. comments
Examples
{{#each issue.comments}}
<!-- Within each, you can use {{this}} for the current comment
{{this.author}}: {{this.body}}
{{/each}}
Detailed information: docs
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
{{setVariable "myCompanyName" "Yasoon GmbH"}}
{{myCompanyName}} <!-- results in Yasoon GmbH -->
{{setVariable "inFiveDays" (addDay now 5)}}
{{inFiveDays}} <!-- results in an ISO-Date 5 days in the future -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET), locale en-US -->
{{format now}} <!-- results in 11/15/2022 -->
{{format now "dateFull"}} <!-- results in November 15, 2022 -->
{{format now "timeSimple" "de-DE"}} <!-- results in 14:15 -->
{{format now "de-DE"}} <!-- NOT ALLOWED, must provide formatKey as well -->
{{format issue.duedate "dateShort" "de-DE"}} <!-- format due date in German locale with dd.mm.yyyy -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{timezone now "utc}} <!-- results in 2022-11-15T13:15:42.000Z -->
{{timezone now "Europe/Berlin"}} <!-- results in 2022-11-15T14:15:42.000+01:00 -->
{{timezone now "America/New_York"}} <!-- results in 2022-11-15T08:15:42.000-05:00 -->
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
{{addDay "2022-11-15" 5}} <!-- results in 2022-11-20T00:00:00.000+01:00 -->
{{addMinute "2022-09-15T13:37:42" 30}} <!-- results in 2019-09-15T14:07:42.000+02:00 -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{subtractYear now 3}} <!-- results in 2019-11-20T14:15:42.000+01:00 -->
{{subtractMinute "10:15" 15}} <!-- results in 2022-11-20T10:00:00.000+01:00 -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{isBeforeDay "2022-11-14" now}} <!-- results in true -->
{{isBeforeHour now "2022-11-15T15:15:42.000+02:00"}} <!-- results in false -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{isBeforeOrSameMinute "2022-11-15T:14:14:59" "2022-11-15T14:15"}} <!-- results in true -->
{{isBeforeOrSameHour now "2022-11-15T15:15:42.000+02:00"}} <!-- results in true -->
{{isBeforeOrSameDay "2022-11-16" "2022-11-15"}} <!-- results in false -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{isSameMinute "2022-11-15T:14:15:59" "2022-11-15T14:15"}} <!-- results in true -->
{{isSameHour now "2022-11-15T15:15:42.000+02:00"}} <!-- results in true -->
{{isSameDay "2022-11-16" "2022-11-15"}} <!-- results in false -->
{{isSameMonth "2022-11-01" "2023-11-10"}} <!-- results in false -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{isAfterOrSameMinute "2022-11-15T:14:16" "2022-11-15T14:15:59"}} <!-- results in true -->
{{isAfterOrSameHour now "2022-11-15T15:15:42.000+02:00"}} <!-- results in true -->
{{isAfterOrSameDay "2022-11-14" "2022-11-15"}} <!-- results in false -->
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
<!-- now is 2022-11-15T14:15:42.000+01:00 (15 November 2022, 14:15.42 CET) -->
{{isAfterMinute "2022-11-15T:14:16" "2022-11-15T14:15:59"}} <!-- results in true -->
{{isAfterHour now "2022-11-15T15:15:42.000+02:00"}} <!-- results in false -->
{{isAfterDay "2022-11-14" "2022-11-15"}} <!-- results in false -->
Known Limitations
sum
function is currently not working. Please use theadd
function instead.