JMWE Cloud: How to format Jira Assets (formerly Insight) date attributes in using Nunjucks

JMWE Cloud: How to format Jira Assets (formerly Insight) date attributes in using Nunjucks

Summary

When retrieving date or date-time attributes from Jira Assets (formerly Insight) using Jira Misc Workflow Extensions (JMWE), the values are often returned as an array/list. If you apply the date filter directly to these arrays, the formatting will fail or return unexpected results. This article explains how to correctly access and format these dates using the first filter or index access.

Use Case: Formatting a Date Attribute from an Assets Object

A common scenario is fetching an Assets object attribute (e.g., "Hire Date") using Nunjucks and needing to display it in a specific date format like YYYY-MM-DD or dddd, MMMM Do YYYY.

Identifying the Issue

When you fetch an attribute value from an Assets object, JMWE can return it in an array/list structure, even if there is only one value.

  • Incorrect Behavior: Applying | date(...) directly to the variable returns a default/fallback date (e.g., "Sunday, January 1st 2023") because the filter cannot process the array object.

  • Verification: Use {{ variable | dump(2) }} to see the raw structure. If you see square brackets [ "..." ], the value is wrapped in an array/list.

Solution: Using the first filter

To format the date correctly, you must first extract the string value from the array using the first filter, then apply the date filter.

Refer to Nunjucks Filters for more information on this filter.

Example Script

The following script demonstrates how to fetch a "Hire Date" from an Assets custom field and format it:

{# Fetch the attribute value which returns an array #} {% set hire_date = issue | insightFieldValue("customfield_11315") | field("attributes.Hire Date[0].value") %} {{ hire_date | dump(2) }} {# WRONG: This will not format correctly as hire_date is an array #} {{ hire_date | date('dddd, MMMM Do YYYY') }} {# CORRECT: Use the 'first' filter to get the date string before formatting #} {{ hire_date | first | date('dddd, MMMM Do YYYY') }}
image-20260515-143646.png

Reference: custom Nunjucks filters used on the provided script