This template displays the number of attachments in the sub-tasks of the current work item.
Configuration
To use the Count attachments in sub-tasks template, simply select it from the template grid. Filter by Sub-tasks to find it faster.
Parameters
This template does not require any additional parameter configuration.
Expert mode
If you switch to Expert mode you can see the formula field in the Expression Parser. You can now tweak the expression to create a custom formula field based on this template.
Expression
Jira expression:
issue.subtasks.map(subtask => subtask.attachments.length).reduce((a, b) => a + b, 0)
Display as
Number
Formatting style
Default (unformatted)
Details
1. What does the expression do?
This expression calculates the total number of attachments across all sub-tasks of the current work item.
2. Step-by-step breakdown
Let’s break it down:
-
issue.subtasks: This refers to the list of all sub-tasks belonging to the current work item. -
.map(subtask => subtask.attachments.length): For each sub-task, this part counts how many attachments it has. The result is a list of numbers, where each number represents the attachment count for a sub-task. -
.reduce((a, b) => a + b, 0): This takes the list of attachment counts and adds them all together, starting from 0. The result is the total number of attachments in all sub-tasks.
3. Examples
Suppose your work item has three sub-tasks:
-
Sub-task 1 has 2 attachments
-
Sub-task 2 has 3 attachments
-
Sub-task 3 has 0 attachments
The expression works as follows:
-
issue.subtasksgives you the three sub-tasks. -
.map(...)turns this into[2, 3, 0]. -
.reduce(...)adds them up: 2 + 3 + 0 = 5.
So, the result is 5.
4. Real-life use cases
-
You want to quickly see how many files or documents are attached to all sub-tasks of a work item, for reporting or tracking purposes.
-
Project managers can use this to monitor documentation completeness.