Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

Filters are essentially functions that can be applied to variables. Filters are called with a pipe operator (|) and can take arguments. This document details custom Nunjucks filters created for JMWE.

...

{{ issue.fields.comment.comments | last | commentProperty("sd.public.comment") | field("internal") }} returns true if the latest comment of the issue is a Jira Service Desk "internal" comment.

componentInfo

componentInfo componentInfo is a custom Nunjucks filter that operates on a component ID, a component object, an array of component IDs, or an array of component objects and takes fieldName as a parameter which is the name of the field to return, or a path using dot notation. If not provided, the full component object is returned.

...

  • <number> is the number of units to add to the date (can be negative)

  • <units> is one of "days", "hours", "weeks" or "months" (or their equivalent: "d", "h", "w", "m")

For example: 

{% set duedate = issue.fields.created | dateadd(2,"w") %} sets the duedate variable to two weeks after the creation date of the issue.

...

This is a custom Nunjucks filter that operates on a user's accountId, a user object, an array of accountIds, or an array of user objects and returns the email address of one or more users. This Nunjucks filter is now the only way to return the email address of a user, since Jira removed the emailAddress property of user objects.

For example:

{{ issue.fields.reporter | emailAddress}} returns the email address of the Reporter. 

{{ issue.fields.Approvers | emailAddress}} returns an array of the emails of the issue's Approvers.

epic

epic is a custom Nunjucks filter that returns the Epic of an issue. If you don't specify which fields to return, you can access all the fields of the Epic, just like with any issue object. 

...

{{issue | epic("status") | field("fields.status.name") returns the name of the status of the Epic.

{{ issue |  epic("key") | field("fields.description") returns the description of the Epic.

{% set stories = issue | epic("key") | stories("status") %} creates a variable 'stories' that holds all stories of the parent Epic of the current issue (i.e. the current issue and all its sibling stories), limiting the fields returned for each story.

Note: For better performance, it is recommended to specify the fields to return, whenever possible.

field

field is a custom Nunjucks filter that returns the value of a field of an object. It applies to an object or an array of objects and takes the field name as a parameter. In the case of an array of objects, it returns an array containing the values of the specified field for each object of the input array. The field name can also be a path (using dot notation). This is useful to access the field of the result of another filter, instead of having to use an intermediate variable.

...

You can inverse the filter using its exclude parameter. Passing true in this parameter returns an array of objects that do not match the search.

For example:

{{ issue.fields.fixVersions | filter({name:"3.0"}) | dump(2) }} filters the fixVersions, for a version with name 3.0 and dumps it in "pretty" JSON format, using 2 spaces as indentation.

{{ issue.fields['MWEC_Check'] | filter({value:"Option 1"}) }} filters the options, for an option with value Option 1 and returns an array containing that option.

{{ issue.fields['MWEC_Group picker'] | filter({}) }} returns all the selected groups.

{{ issue.fields.labels | filter("test") }} filters the array of values, for label test and returns that label in an array.

{{ issue.fields.versions | filter({name:"2.0"} , true) | dump(2) }} filters the fixVersions, for versions that do not have the name 2.0 and dumps them in a "pretty" JSON format, using 2 spaces as indentation.

{{ issue.fields.watches | filter({accountId:issue.fields.reporter.accountId} , true) }}  filters the Watchers, for users that are not the reporter of the issue.

{{issue.fields.comment.comments | filter(["author.active",true]) | join("\n","body")}} returns the body text of all comments made by active users, separated by newlines.

...

This is a custom Nunjucks filter that finds the first element of an array matching the condition, searching for either a value (string) or an object based on the value of a field, and returns an object. When no match is found, null is returned.

For example:

{{ issue.fields.fixVersions | find({name:"3.0"}) | dump(2) }} finds for the first version with the name 3.0 and dumps it in "pretty" JSON format, using 2 spaces as indentation.

{{ issue.fields['MWEC_Check'] | find({value:"Option 1"}) }} finds for the first option with the value Option 1 and returns the option.

{{ issue.fields.components | find({}) }} returns the first component.

{{ issue.fields.labels | find("test") }} finds label test and returns it. Can be useful to check whether the labels field contains a specific label.

...

This is a custom Nunjucks filter that finds the first element of an array of objects matching the condition, searching for the specified value at the specified path. When no match is found, null is returned.

For example:

{{ issue.fields.fixVersions | find("name", "3.0"}) | dump(2) }} finds for the first version with the name 3.0 and dumps it in "pretty" JSON format, using 2 spaces as indentation.

{{issue.fields.comment.comments | find("author.active", true) | field("body") }} returns the body text of the first comment made by an active user.

...

This is a custom Nunjucks filter that returns the list of active users that match a specified string. The string will be searched for in the accountId, emailAddress and displayName fields. This filter returns an array of users. When no match is found, an empty array is returned. Note that the search string is not case-sensitive.

For example:

{{ "Carter" | findUsers | dump(2) }} returns an array of users and dumps it in "pretty" JSON format, using 2 spaces as indentation.

...

By default, only active users are returned, but you can pass true as an optional parameter to return inactive users as well. 

By default, only 50 members are returned, but you can pass a second parameter, maxUsers, and return at most that number of users.

For example:

{{ 'administrators' | groupMembers | join(',',"accountId") }} returns the active users of the administrators group

{{ issue.fields["MWEC_Group picker"] | first | groupMembers(true) | join(',',"accountId") }} returns all (active and inactive) members of the first group of the MWEC_Group picker field

{{ 'jira-administrators' | groupMembers(true,60) | join(',',"accountId") }} returns 60 (active and inactive) members of the jira-administrators group:

To return the active members of all the groups that appear in the "MWEC_group picker" multi-group picker custom field:

...

in is a custom Nunjucks filter that returns true if the input is contained in the parameters, false otherwise. The parameters can be scalar values and/or arrays of scalar values to compare against the input. This applies to any scalar value (string, number, etc.). For example:

{{ "a" | in("a","b") }} outputs true

{{ "a" | in( ["a","b"], "c" ) }} outputs true

{{ issue.fields.project.key | in("TEST","KAN") }} outputs true if the issue belongs to projects TEST or KAN.

{{ issue.fields.assignee.accountId | in(issue.fields.watches | field("accountId"), issue.fields["Request Participants"] | field("accountId")) }} outputs true if the Assignee of the issue is watching the issue or is a requesting participant.

...

{{ issue | initiative("key") | field("fields.description") }} returns the description of the Initiative

{% set epics = issue | initiative("key") | membersOfInitiative("status") %} creates an epics variable that holds all epics of the parent Initiative of the current issue (i.e. the current issue and all its sibling epics), limiting the fields returned for each Initiative.

...

{{issue.fields.reporter | isActiveUser}} returns true if the Reporter of the issue is still active.

isInGroup

The isInGroup filter is a custom Nunjucks filter that returns true if the user is in the specified group name (passed as a parameter to the filter). The user, provided as input to the filter, can be either an accountId or a user object.

...

{{ currentUser | isInGroup("jira-administrators") }} returns true if the current user is in the "jira-administrators" group.

{{ issue.fields.assignee | isInGroup("jira-servicedesk-users") }} returns true if the assignee of the issue is in the "jira-servicedesk-users" group.

isInRole

The isInRole filter is a custom Nunjucks filter that returns true if the user is in the named role (passed as a parameter to the filter). The user, provided as input to the filter, can be either a accountId or a user object. Expected parameters are:

...

{{ currentUser | isInRole("Developers") }} returns true if the logged in user is in the "Developers" project role.

{{ issue.fields.reporter | isInRole("Developers","ARM") }} returns true if the reporter of the current issue is in the "Developers" project role of the project whose key is "ARM"

{{ currentUser | isInRole("Developers",linkedIssue) }} returns true if the logged in user is in the "Developers" project role of the project the first issue linked to the current issue with 'blocks' link type, belongs to.

...

{{ issue | issueProperty("a.property") }} returns the value of the "a.property" property of the current issue

...

This is a custom Nunjucks filter that parses a JSON string and returns the resulting JavaScript Object.

For example:

{% set myObj = '{"f1":"val"}' | JSONparse %}
{{ myObj.f1 }} outputs val

linkedIssues

linkedIssues is a custom Nunjucks filter that returns an array of the issues linked to the current issue, optionally specifying one or more issue link type name(s) as they appear on the issue.

...

{{ issue | linkedIssues('blocks') }} returns an array of issues linked to the current issue with 'blocks' link type.

{{ issue | linkedIssues('blocks', 'is Initiative of') }} returns an array of issues linked with the 'blocks' or 'is Initiative of' link types. 

{{ issue | linkedIssues('blocks', ['status','summary']) }} returns an array of issues linked with the 'blocks' link type, with only the Summary and Status fields. 

{{ issue | linkedIssues('blocks', ['status']) | first | field("fields.status.name")}} returns the name of the status of the first linked issue with the 'blocks' link type.

...

{{ issue | membersOfInitiative("assignee") | last | field("fields.assignee.accountId") }} returns the accountId of the user the last epic belonging to the Initiative is assigned to. 

{{ issue | membersOfInitiative("key") | join(",","key") }} returns the issuekey of all epics of the Initiative, separated by a comma.

...

The optionID filter is a custom Nunjucks filter that returns the Option ID (numerical ID) of an Option value applicable to a select-type field implemented by third party add-ons, such as the Tempo' s Team and Account fields. The filter is applied to a string representing an Option value and takes the fieldNameOrID as a parameter. 

For example:

{{ "Account 1" | optionID("Account") }} returns the numerical ID of the Account whose name is "Account 1"

{{ "Shared Team" | optionID("customfield_14589") }} returns the numerical ID of the Tempo team whose name is "Shared Team"

Note

Note that this filter can be slow. When setting the field to a constant value, it is, therefore, preferable to directly input the numerical ID in the post-function configuration, which you will get by running the Nunjucks expression above in the Nunjucks Tester.

organizationID

The organizationID filter is a custom Nunjucks filter that returns the Jira Service Desk Organization numerical ID of one or more Organization(s). The filter is applied to a string representing an Organization name, or to an array of Organization names.

For example:

{{ "Innovalog" | organizationID }} returns the organization ID of the Organization "Innovalog".

...

{{issue.fields.reporter | organizations | join(",", "name")}} returns a comma-separated list of organization names the Reporter of the current issue belongs to, in the service desk of the current issue
{{currentUser | organizations("SD") | join(",", "id")}} returns a comma-separated list of the IDs of the organizations the current user belongs to in the SD service desk.
{{currentUser | organizations(null) | join(",", "id")}} returns a comma-separated list of the IDs of the organizations the current user belongs to in any service desk.

parentIssue

parentIssue is a custom Nunjucks filter that returns the Parent of the issue. If you don't specify which fields to return, you can access all the fields of the parent, just like with any issue object.

...

{{ issue.key | previousStatus | field("id")}} returns the ID of the previous status

projectInfo

projectInfo projectInfo is a custom Nunjucks filter that operates on an issue (that has the "fields.project.key" field) or a string representing a project key and returns the full details of the project, including versions and components.

...

{{"TEST" | projectInfo }} returns the project information of a project whose key is "TEST"

{{ parentIssue | projectInfo | field("roles") | dump(2) }} returns the project roles of the project the parent issue and dumps it in "pretty" JSON format, using 2 spaces as indentation.

{{ "TEST" | projectInfo | field("components") | find({name:"A"}) | field("lead.accountId") }} returns the accountId of the component lead of component "A" of project "TEST"

{{ "TEST" | projectInfo | field("versions") | last | field("name") }} returns the name of the topmost version on the project's "Releases" tab

...

{{ issue.fields.project | projectProperty("a.property") }} returns  returns the value of the "a.property" property of the current issue's project.

remoteLinks is a custom Nunjucks filter that returns an array of all remote links (for example a Confluence page or an issue in another Jira instance) from the issue. It applies to an issue object or an issue key. 

...

This is a custom Nunjucks filter that returns a comma-separated list of the accountIds or displayNames of the active members (users) of a project role. The input to the filter is the role name. The filter takes two optional parameters:

  • projectRoleName, a String representing the project role name

  • displayNamesIf true, returns display names instead of accountIds

Note that a maximum of 50 users per group role member will be returned.

For example:

{{ 'Administrators' | roleMembers | join(",") }} returns the accountIds of all active users of the Administrators project role

{{ 'Administrators' | roleMembers(true) | join(",") }}returns the displayNames of all active users of the Administrators project role

{{ 'Administrators' | roleMembers("TEST") | join(",") }} returns the accountIds of all members of the Administrators project role of the project whose key is TEST.

{{ 'Administrators' | roleMembers(linkedIssue) }} returns the accountIds of all members of the Administrators project role of the project the linked issue belongs to.

{{ 'Administrators' | roleMembers("TEST", true) }} returns the displayNames of all members of the Administrators project role of the project "TEST"

...

{{ ("project=" + issue.fields.project.key + " order by created desc") | searchIssues(maxResults = 30, fields="summary,description,versions") }} searches for issues in the project of the current issue and returns the first 30 matching issues, ordered by creation date (newer first), returning the summarydescription and Affects Version/s fields.

{{ "project = Test and assignee is empty" | searchIssues(fields="*navigable") }} returns issues that are unassigned in project TEST.

("assignee=" + issue.fields.assignee._accountId) | searchIssues(maxResults = 30) returns the first 30 issues that have the same assignee as the current issue. 

...

{{ "deploymentType" | serverInfo == "Cloud"}} returns true if the deployment type is Cloud (which will obviously always be true)

sprints

sprints is a custom Nunjucks filter that returns the sprints of an issue or a board. It applies to an issue object or a board ID. For an issue, it uses the first scrum board to which the issue's project belongs. It takes an optional state or a list of comma-separated states as a parameter. 

...

{{ 11 | sprints("active") | field("values") | first | dump(2) }} returns first active sprint of the board. You can find the board ID in its URL, after "rapidView="

stories

stories is a custom Nunjucks filter that returns an array of stories associated with the issue (which should be an Epic). If you don't specify which fields to return, you can access all the fields of the parent, just like with any issue object.

For example: 

{{ issue | stories }} returns an array of the stories associated with the Epic. 

...

{{ issue | stories("key") | join(",","key") }} returns the issuekey of all stories of the Epic, separated by a comma.

Note: For better performance, it is recommended to specify the fields to return, whenever possible.

subtasks

subtasks is a custom Nunjucks filter that returns an array of subtasks associated with the current issue. If you don't specify which fields to return, you can access all the fields of the parent, just like with any issue object.

...

This is a custom Nunjucks filter that converts a multi-line text value to html, as expected in the html body in the Email Issue post-function. The newlines are converted to paragraphs and html tags are escaped. The input for the filter is either a multi-line text or a multi-line text field.

...

userProperty(<property key>)

The userProperty filter is a custom Nunjucks filter that returns the value of the user property key (passed as a parameter to the filter) from the user entity properties that are set on the User properties editor page. The user, provided as input to the filter, can be either an accountId or a user object. If the requested user property cannot be found, the filter returns undefined (which is equivalent to an empty string).

For example:

{{ currentUser | userProperty("Location") }} returns the value of the key Location

{{ issue.fields.assignee | userProperty("State") }} returns the value of the key State

usersInOrganization

The usersInOrganization filter is a custom Nunjucks filter that returns the users that belong to a Jira Service Desk Organization. The filter is applied to a number or string representing an Organization ID. If the organization is not found, returns undefined (which is displayed as an empty string).

For example:

{{ 1 | usersInOrganization }} returns the users in the organization whose ID is 1.

{{ "Innovalog" |  organizationID | usersInOrganization }} returns the users of the Organization "Innovalog".

...