I've run into an issue in Jira Automation that looks suspiciously like a bug. I wanted to take the results of a JQL search and total up the number of days between two date values in the results. I first used the Branch Rule widget to search up each issue individually and arrived at a function that properly calculated the number I was looking for. However, the Branching Rule widget cannot pass values back to the main rule, so I was unable to do much of anything useful with this result.
To remedy this, I used the Lookup Issues widget to get the same search results and then used a modified version of the same function (I had to slightly change the smartvalues to remove the "issue." prefix, but otherwise it's the same function, see below). When I did, it seemed incapable of properly calculating the same values. Here's the bug report:
The calculated numbers should equal the number of days between (and including) the startDate and endDate for each issue.
Ex: 10/11-10/11 1 day, 10/17-10/23 7 days, 10/7-10/7 1 day, 10/18-10/18 1 day, 10/8-10/8 1 day
After the first result, there is no rhyme or reason to the results except that they alternate between positive and negative values.
Ex: 10/11-10/11 1 day 10/17-10/23 -5 days 10/7-10/7 5 days 10/18-10/18 -6 days 10/8-10/8 4 days
First thing, what problem are you trying to solve? That is, "why do this?" Knowing that may help the community to offer better suggestions.
Next, and as a short answer: there appear to be field type errors and missing syntax in that iterator expression. Please see details below.
The startDate and endDate are not built-in field's smart values, so I expect at least one is a custom field added to the project / site. What are the types of the fields: text, date picker, date / time picker, etc.?
There is a built-in "Start date" field, with a smart value of the same name. Perhaps use this how-to article to confirm the smart values (or custom field ids) in your expression: https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/
The "Start date" field is a date picker field. If that is the field you wanted to use, why are you formatting that to a text date / time string, and then back to a date / time type before performing the diff() operation? Why not just use the values directly?
Why are you incrementing the "end date" by one day? Is that in the case the dates are the same so the count is always at least 1 day?
Next, your diff() function call is missing the units of measure, and so I would expect the results to be unpredictable. Please review this information to decide which units you need: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-difference---
Kind regards,
Bill
The reason I'm doing this is to capture the difference between two custom date fields.
Through trial and error I found that I had to transform these date values specific ways to get them to be recognized as dates for these functions. Due to the needs of my project, the built-in Start Date is not available, and the number of days in the request is not necessarily the value I want (I will be using a conditional to choose between another date and the start or end dates of these issues once I am able to get past this bug).
The additional day is needed to get the number of days in the range, because the diff function subtracts one from the other, giving you a value that's one less than the number of days the range represents. Again, I am using other functions (the bug has a lot of that stripped away since I was able to establish those transformations were not causing the issue).
Interestingly, I didn't notice that I had left off the units; thank you for calling that out! However, when I included the units in the function, it still provided the same results. I'm going to poke at that some more and make sure I haven't made any other syntax errors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information, Mike!
Just to confirm, you are using Jira Cloud and not Server or Data Center, correct?
What are the types of the custom fields? They seem to be date picker fields, otherwise these would not work with the format() function:
{{startDate.format("M/d")}}-{{endDate.format("M/d")}}
In that case the conversions to / from text should not be needed.
There are some leftover / duplicate smart values in Jira Automation. For example, "Due Date" has several that work! I wonder if there is an existing, old startDate one for the "Start Date" field. The way to force this to work with your fields is to use the custom field ids, for example:
{{issue.customfield_12345.diff(issue.customfield_67890.plusDays(1)).days}}
Perhaps try that with a single, example issue (and your custom field ids) to check for differences.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A single issue doesn't produce the error; it only occurs when trying to take a search result and perform the operation on each issue in the result with the single list command. Taking the command out of the list and using the Branching Results widget provides the correct result. The only reason I'm not using that approach is because I need to sum the values after getting them, and those values can't be passed from the Branching Result to the main part of the rule without storing them outside the rule and retrieving them later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just following up on these questions:
What is your Jira Version: Cloud, Server, or Data Center?
Did you confirm the field types are date picker?
Did you try using the custom field id values rather than the smart values for the field names? For example, with made up ids:
{{#lookupIssues}}
{{customfield_12345.format("M/d")}}-{{customfield_67890.format("M/d")}}
{{customfield_12345.diff(customfield_67890.plusDays(1)).days}}
{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm on Cloud
The fields are from a date picker
I have narrowed down the issue to the diff function. I've removed all of the other variables, to the point where anyone could take my smartvalue and reproduce this in their own instance. I don't believe I'm doing anything here to cause this. However, because I'm on Jira cloud, I can only report the bug through my admin. I didn't want to do that if it turned out I was causing this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information, and I just tried this scenario on a team-managed project and got a similar result, with missing / incorrect values when the difference was negative. The positive diffs all worked for me, however...
I found an open defect for this symptom: https://jira.atlassian.com/browse/AUTO-334
I tried to create a workaround with conversion to milliseconds or epoch time in a list first, and that did not work either.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The issue you're encountering with Jira Automation's diff
function on date values in a list is likely related to how the lookupIssues
smart value is processed within a list. Specifically, there could be an inconsistency in how Jira handles date arithmetic within loops or iterations involving lookupIssues
.
Here’s a breakdown of why this might be happening and possible ways to address it:
Jira DateTime Conversion in Lists: When using lookupIssues
, Jira may not correctly parse or handle date values when used in list processing (loops). This can result in inconsistent behavior when performing date calculations such as diff
.
The inconsistent output you see (alternating positive and negative values) suggests that the way Jira Automation processes these dates inside a list context might not be robust. This could be due to:
lookupIssues
block.Smart Values and Context Changes: In the Branch Rule
approach, the context of the issue is local and confined to the issue being processed at that moment. This allows date manipulations to work correctly. However, in the lookupIssues
approach, the context shifts to an entire list, and the diff
operation might not correctly handle date values because the logic is being applied at a different context level (list versus individual issue).
If possible, use Branch Rule
again but try to summarize or pass data through alternative means (e.g., storing values in variables or passing data using JSON). This way, you ensure that the diff
function runs in the proper context where it works reliably.
lookupIssues
:Modify the way the dates are handled in the lookupIssues
block by isolating each date calculation outside the list processing. You can try something like this:
{{#lookupIssues}}
Start: {{startDate.format("M/d")}}, End: {{endDate.format("M/d")}}
Difference: {{startDate.jiraDate.diff(endDate.jiraDate)}}
{{/}}
This removes the .toDate
and .plusDays(1)
from the calculation. You may also want to ensure both startDate
and endDate
are correctly formatted as dates before performing the diff
operation. Use .jiraDate
instead of .jiraDateTime.toDate
as this could help simplify things.
Ensure both dates (startDate
and endDate
) are consistently formatted in the same time zone and date format. You can try explicitly setting both date fields to use the same date format before applying the diff
calculation, like this:
{{startDate.jiraDate.format("yyyy-MM-dd")}} - {{endDate.jiraDate.format("yyyy-MM-dd")}}
Days: {{startDate.jiraDate.diff(endDate.jiraDate)}}
To further investigate, you could log the raw values for startDate
and endDate
just before the diff
function to verify that the dates are correct and in the expected format:
{{#lookupIssues}}
Start Date Raw: {{startDate}}, End Date Raw: {{endDate}}
{{startDate.jiraDate.diff(endDate.jiraDate)}}
{{/}}
This can help identify if there are any anomalies in the raw date values being processed.
It seems like the diff
function isn't handling the list processing context as expected. Modifying the logic to calculate the difference outside the list, simplifying the date conversion (avoiding .toDate
and plusDays(1)
within the loop), and ensuring both dates are in the same format could help. If the issue persists, it might indeed be a bug, and you could raise it with Atlassian support for further investigation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've tried all of the suggested troubleshooting tips on the lookupIssues approach and they all produce the same result. I am curious how I can pass values from the branch operation to the main operation without going outside Jira Automate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Eduardo
Please stop posting bot-generated content. For more details, please see the community guidelines: https://community.atlassian.com/t5/custom/page/page-id/rules-of-engagement
Thanks,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.