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 value

  • b value to compare if it is equals with a

Examples

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

each

Iterating on a list of values.

Parameters

{{#each array}}...{{/each}}

  • array an array of values, e.g. comments

Examples

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 string

  • value 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 field

  • formatKey string (optional), defaults to dateShort

  • locale string (optional), defaults to the current Atlassian user locale

Examples

 

See table below for all formatKeys

All examples use the ISO date 2022-06-15T14:02:06.123+02:00 and will show the output for locales de-DE as well as en-US, e.g. {{format "2022-06-15T14:02:06.123+02:00" '<format key>' '<locale>'}}

format key

de-DE

en-US

format key

de-DE

en-US

day

15

15

month

06

06

year

2022

2022

yearShort

22

22

weekday

Mittwoch

Wednesday

weekdayShort

Mi

Wed

dateShort

15.6.2022

6/15/2022

dateMed

15. Juni 2022

Jun 15, 2022

dateMedWithWeekday

Mi., 15. Juni 2022

Wed, Jun 15, 2022

dateFull

15. Juni 2022

June 15, 2022

dateHuge

Mittwoch, 15. Juni 2022

Wednesday, June 15, 2022

timeSimple

14:02

2:02 PM

timeWithSeconds

14:02:06

2:02:06 PM

timeWithShortOffset

14:02:06 MESZ

2:02:06 PM GMT+2

timeWithLongOffset

14:02:06 Mitteleuropäische Sommerzeit

2:02:06 PM Central European Summer Time

time24Simple

14:02

14:02

time24WithSeconds

14:02:06

14:02:06

time24WithShortOffset

14:02:06 MESZ

14:02:06 GMT+2

time24WithLongOffset

14:02:06 Mitteleuropäische Sommerzeit

14:02:06 Central European Summer Time

dateTimeShort

15.6.2022, 14:02

6/15/2022, 2:02 PM

dateTimeShortWithSeconds

15.6.2022, 14:02:06

6/15/2022, 2:02:06 PM

dateTimeMed

15. Juni 2022, 14:02

Jun 15, 2022, 2:02 PM

dateTimeMedWithSeconds

15. Juni 2022, 14:02:06

Jun 15, 2022, 2:02:06 PM

dateTimeMedWithWeekday

Mi., 15. Juni 2022, 14:02

Wed, Jun 15, 2022, 2:02 PM

dateTimeFull

15. Juni 2022, 14:02 MESZ

June 15, 2022, 2:02 PM GMT+2

dateTimeFullWithSeconds

15. Juni 2022, 14:02:06 MESZ

June 15, 2022, 2:02:06 PM GMT+2

dateTimeHuge

Mittwoch, 15. Juni 2022, 14:02 Mitteleuropäische Sommerzeit

Wednesday, June 15, 2022, 2:02 PM Central European Summer Time

dateTimeHugeWithSeconds

Mittwoch, 15. Juni 2022, 14:02:06 Mitteleuropäische Sommerzeit

Wednesday, June 15, 2022, 2:02:06 PM Central European Summer Time

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 string

  • zone 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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

  • isoDate2 string, If only a date and no time is provided like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

  • isoDate2 string, If only a date and no time is provided like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

  • isoDate2 string, If only a date and no time is provided like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

  • isoDate2 string, If only a date and no time is provided like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-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 like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

  • isoDate2 string, If only a date and no time is provided like 2015-11-15 it will be converted internally to 2015-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 2022 13:01 will be converted to 2015-11-15T13:01.00.000.

Examples

 

Known Limitations

  • sum function is currently not working. Please use the add function instead.