Breadcrumbs

Earliest date from linked work items

📚

Return the earliest date from a Date Picker custom field in the linked work items of the current work item.

Configuration

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

Expression

let minDate = issue?.links.map(link => link.linkedIssue.customfield_nnnnn).filter(
d => d != null);
minDate.length > 0 ? new CalendarDate(minDate.reduce((a, b) => a < b ? a : b ))
.toString() : ""

Please, replace nnnnn with the ID of a Date Time Picker custom field.

Details

1. What does the expression do?

This expression finds the earliest date from a specific Date Picker custom field across all work items that are linked to the current work item. It returns this earliest date as a string. If no linked work items have a date set, it returns an empty string.

2. Step-by-step breakdown

Let’s break it down:

  • issue?.links: Gets all the links of the current work item.

  • .map(link => link.linkedIssue.customfield_nnnnn): For each linked work item, it retrieves the value of a specific Date Picker custom field (replace nnnnn with your actual custom field ID).

  • .filter(d => d != null): Removes any entries where the date field is empty or not set.

  • let minDate = ...: Stores the list of all non-empty dates from the linked work items.

  • minDate.length > 0 ? ... : "": Checks if there are any dates found. If not, it returns an empty string.

  • minDate.reduce((a, b) => a < b ? a : b ): Finds the earliest (minimum) date in the list.

  • new CalendarDate(...).toString(): Converts the earliest date into a readable string format.

3. Examples

Suppose you have three linked work items with the following dates in the custom field:

  • Linked work item A: 2024-05-01

  • Linked work item B: 2024-04-15

  • Linked work item C: (no date set)

The expression will:

  • Collect the dates: [2024-05-01, 2024-04-15]

  • Filter out the empty value (from C)

  • Find the earliest date: 2024-04-15

  • Return "15/Nov/24" as the result

If none of the linked work items have a date set, the result will be an empty string.

4. Real-life use cases

  • You want to display the earliest planned start date among all tasks linked to a project work item.

  • You need to track the soonest deadline among all sub-tasks or related work items.

  • You want to automate reporting by always showing the earliest relevant date from a group of related work items.