Velocity
Syntax
This section is a subset of what you can do with Velocity
For a full guide, see the official Apache Velocity user guide.
Elements Connect uses the Velocity provided by Jira.
Single line comments |
CODE
|
Multi-lines comments |
CODE
|
Set a variable |
CODE
|
Access a variable | Shorthand notation:
CODE
Formal reference notation (useful when you want to concatenate a velocity variable to a preset text)
CODE
Quiet reference notation: evaluate non resolved variable to an empty string (blank)
CODE
|
Loops |
CODE
|
Conditional |
CODE
|
Relational and logical operators |
CODE
CODE
CODE
CODE
|
Escaping Valid VTL References |
CODE
renders as
CODE
|
Maths | Velocity has a handful of built-in mathematical functions that can be used in templates with the set directive.
CODE
|
Range operator | The range operator can be used in conjunction with #set and #foreach statements. Useful for its ability to produce an object array containing integers, the range operator has the following construction:
CODE
example:
CODE
|
Variables
Global variables
Those variables can be used in queries, in Root element and in Columns JSON path.
Type | Name | Description | Available in |
---|---|---|---|
List<string> For fields of any type but Live User | $currentCustomfieldValue | Value currently stored in the Elements Connect field. This variable works only for Live fields and not for Snapshot fields (see CO-3752) | All queries Empty when the field does not have any value. |
List<user> For fields of type Live User | |||
$currentUser | Current user connected on the screen. | All queries | |
$currentUserLocale | Locale of the current user (ie: fr_FR, no_NO, ...) | All queries | |
$issue | Current issue | All queries, expect the "Dashboard Gadget" view of the display query. | |
Velocity | $query | Direct access to the query to execute | All queries |
$userInput | Characters typed by the user in the autocomplete text box. | Edit query when the editor is set to "Autocomplete". | |
Velocity | $util | Set of useful functions | All queries |
$context | Current context of the Search query | Search query |
Note about types and list of types
In our descriptions, we sometimes say that functions and variables return certain type or list of types. There is no difference in the way we handle this. This is explain in details in the Simple and multiple types section below.
Date
Attributes
Type | Name | Description |
---|---|---|
isoDate | Iso date format 'yyyy-MM-dd'. ex: 2015-02-22 | |
isoDateTime | Iso date time format 'yyyy-MM-dd HH:mm:ss.SSS'. ex: 2015-08-22 17:31:15.123 | |
isoDateTimeZone | Iso date time zone format 'yyyy-MM-dd HH:mm:ss.SSSXXX'. ex: 2015-08-22 17:31:15.123+02:00 |
Functions
Any function string is applicable on Date. In that case, the date is first converted into a String using the historical format 'EEE MMM dd HH:mm:ss zzz yyyy'.
In short, date.serialize(" ") is equivalent to date.format("EEE MMM dd HH:mm:ss zzz yyyy").serialize(" ")
Return type | Name | Description |
---|---|---|
format("...") | This function allows you to format your date freely, if you need a specific formatting. |
The ISO-8601 date format ('yyyy-MM-dd HH:mm:ss.SSSXX' ie '2015-08-22 17:55:01.123+02:00' is understood by most of databases.
Issue
Attributes
Type | Name | Description |
---|---|---|
List<named-value> | affectedVersions | Affected versions |
assignee | Issue assignee | |
List<named-value> | components | Components |
created | Date when the issue has been created | |
creator | Issue creator | |
date or | customfield_xxxx | A custom field value - xxxx is the field id >> Return a List if the field contains multiple values The return type depends on the type of the custom field. If this is a date custom field (Date or Datetime picker), the return type is a dat. If this is a third party add-on custom field, you can have a look Customfields In any other case, the value is returned as a st. |
description | Description | |
duedate | Issue due date | |
environment | Environment | |
estimate | Estimate | |
List<named-value> | fixVersions | Fix versions |
id | ID Only available on existing issues, on the "Create issue" screen this variable is empty (the issue does not exists) | |
issuetype or issueType | Issue type | |
key | Key Only available on existing issues, on the "Create issue" screen this variable is empty (the issue does not exists) | |
originalEstimate | Original estimate | |
parent | Parent of the issue | |
priority | Priority | |
project | Project key of the the current issue | |
reporter | Issue reporter (note: not available on the Create issue screen) | |
resolution | Resolution | |
resolutiondate | Content of the "Resolution date" field | |
resolutionDate | Content of the "Resolution date" field (since 5.9.3) | |
security | Security level | |
status | Status | |
summary | Summary | |
timeSpent | Time spent | |
updated | Date when the issue has been updated for the last time | |
vote | This field is deprecated (mispelled). It is still supported for now but we recommend to use votes below instead. | |
votes | Votes count (since 5.9.3) | |
watchers | This field is deprecated (mispelled). It is still supported for now but we recommend to use watches below instead. | |
watches | Watchers count (since 5.9.3) |
Functions
Any function string is applicable on Issue.
Return type | Name | Description |
---|---|---|
date or | get("<custom field name>") or get("customfield_xxx") |
Not recommended We do not recommend to use this function. You shall use the customfield_xxxx notation described above. >> The return type depends on the type of the custom field A custom field value - xxxx is the field id >> Return a List if the field contains multiple values The return type depends on the type of the custom field. If this is a date custom field (Date or Datetime picker), the return type is a d. If this is a third party add-on custom field, you can have a look c In any other case, the value is returned as a st. Not for System fields: This is only available for custom fields (native or brought by third party). For system fields, please use notation described abobe (ie. $issue.summary). |
Named value
Attributes
By default a named value is evaluated to its name.
Functions
Any function string is applicable on Name value.
Project
Attributes
By default, a Project is evaluated to its key.
Categories
Type | Name | Description |
---|---|---|
id | The project category id (ex: $issue.project[0].projectCategory.id) | |
name | The project category name (ex: $issue.project[0].projectCategory.name) | |
description | The project category description (ex: $issue.project[0].projectCategory.description) |
Functions
Any function string is applicable on Project.
The string value used in the evaluation will be the project key.
Query
Direct access to the query to execute - only available in the URL Path / Query attributes of a field configuration.
Name | Description | Example |
---|---|---|
abort() | If this instruction is encountered during the evaluation of the query, the query won't be executed. It is useful if we know in advance that the query won't return any result if certain conditions are not met. | In this example, the query is aborted if the summary of the issue is empty. #if($issue.summary.length() == 0) |
String
Functions
Return type | Name | Description | Example |
---|---|---|---|
Integer | length() | Returns the String length | $issue.customfield_xxxxx.length() > 42 |
intList() | Shortcut for $var.serialize(",") | $issue.affectedVersions.id.intList() > 10000,10001,10002 | |
prefix(<string>) | Append a string before the string | $issue.issuetype.prefix("hello ") > hello Bug | |
replace(<old str>, <new str>) | Replace first string by another string | #set($variable = 'User story') > User tale | |
replaceAll(<old str>, <new str>) | Returns a new string in which all occurrences of the first parameter are replaced by the second parameter. The first parameter can be a string or a regex. | #set($variable = 'Jira (v8.6.1)') | |
serialize(<string>) | Join the string using a delimiter | $issue.affectedVersions.name.serialize(";") > 1.0;1.1;1.2 | |
stringList() | Append ' before and after each string and serialize them with a , separator | $issue.affectedVersions.id.stringList() > '1.0','1.1','1.2' | |
suffix(<string>) | Append a string after the string | $issue.issuetype.suffix(" world") > Bug world | |
urlEncode() | Convert all characters to be readable in an URL | $issue.summary.urlEncode() > Elements Connect+in+a+nutshell | |
encodeURIComponent() | Convert a text to be readable in an URL parameter. | $issue.description.encodeURIComponent() > hello%20world%20%3F | |
encodeURI() | Convert a text to be readable in an URL. | $issue.description.encodeURI() > https%3A%2F%2Fvaliantys.atlassian.net%2Fsecure%2FDashboard.jspa |
User
Attributes
Type | Name | Description |
---|---|---|
displayName | Display name of the user | |
emailAddress | Email address of the user | |
name | Name of the user | |
userName | Username of the user |
Functions
Any function string is applicable on User.
The string value used in the evaluation will be the user name.
Return type | Name | Description |
---|---|---|
boolean | isInGroup(<jira group>) | Is the user member of the given group ? |
boolean | isInProjectRole(<role name>,<project key>) | Does the user have the role in the project ? |
Util
Functions
Return type | Name | Description | Example |
---|---|---|---|
Raw text | encodeURIComponent(<string>) | Convert a text to be readable in an URL parameter. | $util.encodeURIComponent("hello world ?") > hello%20world%20%3F |
Raw text | encodeURI(<string>) | Convert a text to be readable in an URL. | $util.encodeURI("https://valiantys.atlassian.net/secure/Dashboard.jspa") > https%3A%2F%2Fvaliantys.atlassian.net%2Fsecure%2FDashboard.jspa |
Context
Attribute
Type | Name | Description | Example |
---|---|---|---|
| Current execution context |
CODE
|
Constants
This constants are available in the query of the Search view.
They can be used to determine the execution context of the query and thus to know which velocity variable can be used in the current context
Type | Name | Description |
---|---|---|
SEARCH_BASIC_GENERATE_OPTIONS | Generate options list in the basic search mode Velocity variables available:
| |
SEARCH_BASIC_GENERATE_JQL_QUERY | Generate the JQL query from the option selected in the basic search mode Velocity variables available:
| |
SEARCH_ADVANCED_GENERATE_OPTIONS | Generate options list in the advanced search mode Velocity variables available:
| |
SEARCH_ADVANCED_TILDE_SEARCH | Evaluation of ~ and !~ clauses in the advanced search mod Velocity variables available:
|
Custom fields
Option fields
Elements Connect supports options fields like radio buttons, checkboxes or select list
Type | Name | Description | Example |
---|---|---|---|
| Returns the name of the selected option (first option in case of multi select) | $issue.customfield_10005.getOptionName() > Red | |
List<string> |
| Returns the names of the selected options | $issue.customfield_10005.getOptionName().stringList() > 'Red', 'Blue', 'Green' |
| Returns the ID of the selected option (first option in case of multi select) | $issue.customfield_10005.getOptionId() > 10001 | |
List<string> |
| Returns the IDs of the selected options | $issue.customfield_10005.getOptionIds().intList() > 10001, 10002, 10003 |
Jira software
Type | Name | Description | Example |
---|---|---|---|
List<string> |
| Display the Issue sprints names | Current Issue is in one sprint: "Welcome to the Jungle"
Current Issue is in two sprints: "Welcome to the Jungle" and "Hells Bells"
10005 is the ID of the Sprint field |
List<string> |
| Display the Issue sprints ids | Current Issue is in one sprint, with ID 10002
Current Issue is in two sprints, with ID 10002 and 10003
10005 is the ID of the Sprint field |
Jira Service Management
Type | Name | Description | Example |
---|---|---|---|
List<string> |
| Display the request organization names | Current request is shared with one organization: "My fantastic organization"
Current request is shared with two organizations: "My fantastic organization" and "Customers first"
10002 is the ID of the Organization custom field |
List<string> |
| Display the request organization ids | Current request is shared with one organization, with ID 6
Current request is shared with two organizations, with ID 6 and 7
10002 is the ID of the Organization custom field |
Tempo Accounts
Tempo Timesheets add-on for JIRA embeds a specific customfield type named Accounts. Elements Connect allows to retrieve data from this customfield this way
Type | Name | Description | Example |
---|---|---|---|
customfield_xxxxx | Display the display value of selected Account | $issue.customfield_10001 > Account 1 (ACCOUNT1) | |
customfield_xxxxx.id | Display the id of selected Account | $issue.customfield_10001.id > 2 | |
customfield_xxxxx.name | Display the name of selected Account | $issue.customfield_10001.name > Account 1 |
Simple types and multiple types
In the descriptions above, variables and functions are said to return a specific type or a list of values of this type. This is handled exactly the same way by our API.
In short, any single value is considered being a list with a unique value. This allows to apply any function or attribute to any value without the need to check its size.
The only exception is when we convert the expression to a String value for final query evaluation. If there are many elements in a list, we only display the first one (See the examples below).
Example:
Context | Expression | Result | Explanation |
---|---|---|---|
Issue with one fix version "1.2" |
| 1.2 | N/A |
Issue with two fix versions "1.2" and "1.3" |
| 1.2 | When we need to evaluate a query like "SELECT * FROM XXX where version='$issue.fixVersion'", we only take the first element if there are many. To use the other elements, you need alternate expressions (see below) |
Issue with two fix versions "1.2" and "1.3" |
| '1.2', '1.3' | This way you can write "SELECT * from XXX where version in ($issue.fixVersions.stringList()) |
Issue of type 'Bug' |
| Bug | |
Issue of type 'Bug' |
| Bug | As this is considered as a list of one issue type, you can apply the function serialise to it. This only has one element. As you may also have noticed, the serialize function need a string input, and the default string evaluation for issue type (Named Value) is 'name'. The expression is equivalent to $issue.issuetype.name.serialize("; " |