Functions

Intelligent reports provides the following functions which can be used in your calculations.

count

The count function returns the number of items in a list of any type of object.

count(all.projects)
count(questions.Project.versions)

max

The max function returns the maximum value from a list of numbers.

max(jql("\"Story Points\" is not empty")."Story Points")

min

The min function returns the minimum value from a list of numbers.

min(jql("\"Story Points\" is not empty")."Story Points")

sum

The sum function adds up all of the numbers in a list and returns their sum.

sum(jql("\"Story Points\" is not empty")."Story Points")

average

The average function returns the average of a list of numbers.

average(jql("status = Done")."Time Spent")

jql

The jql function takes a string and executes it as a JQL query, returning the list of issues specified by the query.

jql("status = Done")

if

The if function is used to select between two values based on a condition. The condition is the first argument and must evaluate to a boolean. The second argument is the value to use if the condition is true, the third argument is the value to use if the condition is false. The second and third arguments must both be of the same type, for example they could both be strings, or they could both be lists of issues.

if(count(jql("project={questions.Project}")) != 0, "The project has issues", "The project does not have any issues")

filter

The filter function is used to remove elements you do not want from a list. It takes two arguments. The first argument is the list to work on. The second argument is a single argument function that takes in the element of the list, and returns true to keep the element, or false to remove the element from the list. The function argument is usually declared using anonymous function syntax.

filter(all.Projects, project -> find("public", project.name) != -1)

map

The map function is used to transform each element of a list by a function. The first argument is the list to work on, the second argument is a single argument function that takes in an element from the list, and returns the value to put in the output list. The function argument is usually declared using anonymous function syntax.

map(all.Projects, project -> sum(jql("project={project}")."Story Points"))

concatenate

The concatenate function joins a list of strings into a single string.

concatenate(jql("status = Done")."Key")

find

The find function finds the first instance of one string in another. It returns the index of the first occurrence. The first argument is the string to find. The second argument is the string to search in.

find("-", question.Issue."Key")

replace

The replace function replaces every occurence of one string with another in the given string. The first argument is the string to find, the second is the string to replace it with, and the third is the string to do the replacements in.

replace("-", "", question.Issue."Key")

substring

The substring function returns a substring of the given string. The first argument is the full string to take the substring of, the second argument is the first index to start the substring from. The optional third argument is the last index to copy to (non-inclusive).

substring(question.Issue."Key", 4)

number

The number function transforms a string into a number. If Intelligent Reports cannot convert the specified string into a number the report will not be generated and an error will be shown to the user.

number("7")

now

The now function returns the current date and time.

now()

datetime

The datetime function takes in a date object as an argument and returns a datetime object corresponding to midnight on the given date.

You may need this function if you are using a JIRA field that returns a date, but want to use one of the calculations functions or methods that only apply to datetime objects.

datetime(issue.duedate)

minDate

The minDate function returns the minimum (oldest) date in a list of datetime objects.

minDate(jql("project={questions.Project}")."created")

maxDate

The maxDate function returns the maximum (most recent) date in a list of datetime objects.

maxDate(jql("project={questions.Project}")."created")

durationInSeconds

The durationInSeconds function resturns the number of seconds between two datetime values. If the end value is before the start value, a negative number will be returned.

durationInSeconds(now(), now().addDays(1))

listDaysBetween

The listDaysBetween function returns a list of dates corresponding to days between the two given dates. The returned days will have the same time component as the first argument. The first argument is a date and time to start from. This date will be included in the returned dates. The second argument is the date to finish at. This date will not necessarily be included in the list of returned dates, however the last returned value will be within 24 hours of the second argument date. There is an optional third argument which allows you to list values with multiple days between them. For example if the third argument is 7, the listed days will be 7 days apart.

listDaysBetween(now().startOfMonth(), now().endOfMonth())
listDaysBetween(now().startOfMonth().addMonths(-6), now().endOfMonth(), 7)

listWeekDaysBetween

The listWeekDaysBetween function returns a list of dates corresponding to week days between the two given dates. This function works in a similar manner to the listDaysBetween function with the exception of not including weekends. Note that public holidays that fall on week days will still be included.

listWeekDaysBetween(now().startOfMonth(), now().endOfMonth())
listWeekDaysBetween(now().startOfMonth().addMonths(-6), now().endOfMonth(), 7)    

listMonthsBetween

The listMonthsBetween function returns a list of dates corresponding to months between the two given dates. The returned dates will have the same day of month and time component as the first argument. The first argument is a date and time to start from. This date will be included in the returned dates. The second argument is the date to finish at. This date will not necessarily be included in the list of returned dates, however the last returned value will be within 1 month of the second argument date. There is an optional third argument which allows you to list values with multiple months between them. For example if the third argument is 3, the listed dates will be 3 months apart.

listMonthsBetween(now().startOfYear(), now().endOfYear())
listMonthsBetween(now().startOfYear(), now().endOfYear(), 3)

listYearsBetween

The listYearsBetween function returns a list of dates corresponding to years between the two given dates. The returned dates will have the same month, day of month and time component as the first argument. The first argument is a date and time to start from. This date will be included in the returned dates. The second argument is the date to finish at. This date will not necessarily be included in the list of returned dates, however the last returned value will be within 1 year of the second argument date. There is an optional third argument which allows you to list values with multiple years between them. For example if the third argument is 10, the listed dates will be 10 years apart.

listYearsBetween(now().startOfYear().addYears(-4), now().endOfYear())
listYearsBetween(now().startOfYear().addYears(-50), now().endOfYear(), 10)

intersection

The intersection function takes in two lists of objects and returns a list containing only the objects that appear in both lists. For example:

intersection([1,2,3], [3,4,5])

will return a new list with the single object: [3]

union

The union function takes in a list of lists and returns a list with all of the lists joined together. For example:

union([[1,2,3], [4,5], [6]])

will return a new list with 6 elements: [1,2,3,4,5,6]

unique

The unique function takes in a list of objects and returns a list with only unique elements of the input list. For example:

unique([4,5,5,5,6,6,7])

will return a new list with 4 elements: [4,5,6,7]

issueFieldAt

The issueFieldAt function returns the value of a field of an issue at a particular date and time. The issueFieldAt function takes three arguments:

  1. The issue containing the field

  2. The name of the issue field

  3. The date and time

For example:

issueFieldAt(questions.Issue, "Remaining Estimate", now().addDays(-7))

will return the value held by the Remaining Estimate field of the issue specified by questions.Issue 7 days ago.

regexMatch

The regexMatch function matches a regular expression against a string and returns the first match found. The regexMatch function takes two required arguments and two optional arguments:

  1. The regular expression. You can use any of the syntax specified in the Java regular expression syntax. This is a required argument.

  2. The string to match against with the regular expression. This is a required argument.

  3. The number of the group in the match to return. This is an optional argument. Group 0 (the default if no group is specified) is the entire match, group 1 is the first parentheses group match in the regular expression, and so on.

  4. The flags argument to the regular expression parser. This is an optional argument. This is a string which may contain the following characters in any order:

  • "i" allows for case insensitive matching.

  • "d" allows the expression . to match any character, including a line terminator.

  • "m" allows the expressions ^ and $ to match the start and end of each line in the string. If the m flag is not specified ^ and $ only match the beginning and end of the entire string.

The regexMatch function returns the string of the given group or the entire match if no group was specified. If the regular expression does not match, the regexMatch function returns null.

For example:

regexMatch("[A-Z]+\\-([0-9]+)", repeating.item."Key", 1)

will return the numbers from the issue key. For example, "14" from "TEST-14".

regexReplace

The regexReplace function replaces every portion of a string matched by a regular expression with another string. The regexReplace function takes three required arguments and one optional argument:

  1. The regular expression. You can use any of the syntax specified in the Java regular expression syntax. This is a required argument.

  2. The string to replace the regular expression match with. This will be processed by the Java Matcher.replaceAll method, so backslash and dollar sign characters will be treated specially as described in the <a href="https://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#replaceAll(java.lang.String)">Matcher.replaceAll documentation</a>. This is a required argument.

  3. The string to match against with the regular expression and then replace the match with the second argument. This is a required argument.

  4. The flags argument to the regular expression parser. This is an optional argument. This is a string which may contain the following characters in any order:

  • "i" allows for case insensitive matching.

  • "d" allows the expression . to match any character, including a line terminator.

  • "m" allows the expressions ^ and $ to match the start and end of each line in the string. If the m flag is not specified ^ and $ only match the beginning and end of the entire string.

The regexReplace function returns the string of the third argument with every match of the regular expression replaced with the string of the second argument. If the regular expression does not match, the regexReplace function returns the third argument unmodified.

For example:

regexReplace("[A-Z]+\\-", "PROJECT-", repeating.item."Key")

will return the replace the project name and dash in the issue key with "PROJECT-". For example, "TEST-14" will become "PROJECT-14".

transitions

The transitions function returns a list of transitions that a particular issue has undergone optionally filtered by the field, from value (the value before the transition) and the to value (the value after the transition). The transitions function takes four arguments:

  1. The issue for which transitions will be provided

  2. A field name to restrict transitions to. This argument should be specified as a string. Specifiying "ANY" will return the transitions for all fields.

  3. A from value. Specifying a from value will restrict transitions to only those where the value before the transition matches the specified value. This argument should be specified as a string even for non-string values such as numbers. Specifying "ANY" will return all transitions regardless of the from value.

  4. A to value. Specifying a to value will restrict transitions to only those where the value after the transition matches the specified value. This argument should be specified as a string even for non-string values such as numbers. Specifying "ANY" will return all transitions regardless of the to value.

For example:

transitions(questions.Issue, "status", "ANY", "ANY")

will return all transitions of the field status of the issue specified by questions.Issue.

Still have questions? Contact our friendly support team, we are here to help!