Accessing fields of a subtask or a parent

Abstract

This code snippet accesses the fields of a subtask or a parent issue

Logic

You cannot access all the sub-fields of a subtask or a parent using the "Sub-tasks" field {{ issue.fields['Sub-tasks'] }} or the "Parent" field {{issue.fields["Parent"] }} respectively. This is a Jira Cloud limitation. It only returns a subset of fields of the issue in context and not all the sub-fields. 

To access the fields of a subtask: Use the subtasks filter on the issue to get the subtasks. Access a subtask using the first/last/find/filter filter, whichever is applicable and then the field filter to access a field of the subtask

To access the fields of a parent issue: Use the parent filter on the issue to get the parent of the issue and the field filter to access the fields of the parent issue.

Snippet

To access a field of a subtask

{{ issue | subtasks | <filter> | field("fields.<fieldId>") }}

or

{{ issue | subtasks | <filter> | field("fields['<fieldName>']") }}

To access a field of a parent issue

{{ issue | parentIssue | field("fields.<fieldId>") }}

or

{{ issue | parentIssue | <filter> | field("fields['<fieldName>']") }}

Placeholders

PlaceholderDescriptionExample
<Name of the field>Name of the fieldcomponents
<filter>Filter to fetch a subtasklast

Examples

The outcome of the code snippet is an issues' field value which can be used to

  • Set the field value of another issue
  • Compare the field value to a constant in a conditional execution statement

For example: 

  • Fetch the Component/s of the first subtask of the parent

    {{ issue | subtasks | first | field("fields.components") }}

    or

    {{ issue | subtasks | first | field("fields['Component/s']")}}
  • Fetch the Affects Version/s of the last subtask of the parent

    {{ issue | subtasks | last | field("fields.versions") }}

    or

    {{ issue | subtasks | last | field("fields['Affects Version/s']")}}
  • Fetch the Assignee of the first subtask reported by the current user

    {{ issue | subtasks  | find("fields.reporter.accountId" , currentUser.accountId ) }}

    or

    {{ issue | subtasks  | find("fields['Reporter'].accountId" , currentUser.accountId ) }}
  • Fetch the Assignee of the parent

    {{ issue | parentIssue | field("fields.assignee") }}

    or

    {{ issue | parentIssue | field("fields['Assignee']") }}

References