Breadcrumbs

Operations with field values from sub-tasks

📚

Return the result of summing the multiplication of the field values of two Number fields in every sub-task of the current work item.

Configuration

Create a Custom smart number field and use the Jira expression parsing mode.

Expression

issue.subtasks.length && issue.subtasks.map( s => (s.customfield_nnnnn || 0) * 
(s.customfield_ppppp || 0)).reduce((a, b) => a + b)

Please, replace nnnnn and ppppp in the above expression with the IDs of the Number fields.

Display as

Number

Formatting style

Default (unformatted)

Details

1. What does the expression do?

This expression calculates the sum of the products of two specific number fields for every sub-task of the current work item. In other words, for each sub-task, it multiplies the values of two chosen number fields together, then adds up all those results to give a single total.

2. Step-by-step breakdown

Here’s the expression:

issue.subtasks.length && issue.subtasks.map(s => (s.customfield_nnnnn || 0) * (s.customfield_ppppp || 0)).reduce((a, b) => a + b)

Let’s break it down:

  • issue.subtasks.length && ...

    • Checks if there are any sub-tasks. If there are none, the result is 0.

  • issue.subtasks.map(s => ...)

    • Goes through each sub-task (s) of the current work item.

  • (s.customfield_nnnnn || 0)

    • Gets the value of the first Number field (replace nnnnn with the actual field ID). If the field is empty or missing, it uses 0.

  • (s.customfield_ppppp || 0)

    • Gets the value of the second number field (replace ppppp with the actual field ID). If the field is empty or missing, it uses 0.

  • (s.customfield_nnnnn || 0) * (s.customfield_ppppp || 0)

    • Multiplies the two field values for each sub-task.

  • .reduce((a, b) => a + b)

    • Adds up (sums) all the multiplication results from each sub-task.

3. Examples

Suppose you have three sub-tasks, and you want to multiply the values of "Estimated Hours" (customfield_10001) and "Hourly Rate" (customfield_10002) for each sub-task, then sum the results:

  • Sub-task 1: Estimated Hours = 2, Hourly Rate = 50 → 2 * 50 = 100

  • Sub-task 2: Estimated Hours = 3, Hourly Rate = 60 → 3 * 60 = 180

  • Sub-task 3: Estimated Hours = 1, Hourly Rate = 40 → 1 * 40 = 40

Total = 100 + 180 + 40 = 320

4. Real-life use cases

  • Calculating total cost: If each sub-task has a "quantity" and a "unit price" field, this expression gives you the total cost across all sub-tasks.

  • Summing weighted values: If you track "effort" and "priority" as numbers, you can get a weighted effort score for all sub-tasks.

  • Project management: Quickly aggregate metrics like total estimated work, cost, or other calculated values from sub-tasks for reporting or dashboards.