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.

...

{{ 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.

...

{{issue | epic("status") | field("fields.status.name") returns the name of the status 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.

...

{{ 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_Check'] | find({value:"Option 1"}) }} finds for the first option with the value Option 1 and returns the option.

...

{{ 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', ['status','summary']) }} returns an array of issues linked with the 'blocks' link type, with only the Summary and Status fields. 

...

{{ 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.

...

{{ ["Innovalog","Tempo"] }} returns the organization IDs of the Organizations "Innovalog" and "Tempo".

organizations

The organizations Nunjucks filter returns the Organizations a user belongs to. It applies to a user object or an accountId string, and takes an optional projectKeyOrIssue parameter that is either the project key of the service desk in which to look for the organizations, or an issue object in whose service desk to look for the organizations. If not specified, the filter returns organizations from the service desk to which the target issue belongs. If null is specified, the filter will return all organizations to which the user belongs, in any Service Desk.

For example:

{{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.

...

{{ 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"

...

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. 

...

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.

...

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.

...