Diff not working as expected in lookupIssues loop

Zoe Harris
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 27, 2024

Hi there!

I am currently working on a automation project in which I need to send an email with certain informations from a list of lookupIssues tikckets. One of these informations is to get the difference between the fixVersion startDate and fixVersion releaseDate. To do so, I work with smart values. Here's the code:

{{#lookupIssues}}
    {{fixVersions.first.startDate.diff(fixVersions.first.releaseDate)}}

{{/}}

(the .first is because fixVersions are lists but we are sure that there will always be only one fix version per ticket so it's fine)

As you can see, by code is pretty simple, with a lookupIssues list that contains for now two tickets:

1st ticket: fixVersion startDate is 17 June 2024, fixVersion releaseDate is 27 June 2024.
2nd ticket: fixVersion startDate is 14 May 2024, fixVersion releaseDate is 18 May 2024

As you can see, if you do the difference between the startDate and the releaseDate of each ticket, the result should be 10 for the first and 14 for the second. However, when I test this, the result is 10 and 44. 

 

Here's the automation and the result.

image.png

image.png

The only thing I can notice here is that the code somehow does the difference between the startDate of the current ticket and the releaseDate of the first ticket, as the difference between May 14th and June 27th is in fact 44 days. 

Keep in mind that I cannot use a foreach loop as I send an email that will be sent too many times in a loop. I don't understand why this doesn't work as expected, and why it semingly takes only the value from the first ticket in the list for the difference. Can anyone help me figure this one out?

1 answer

1 vote
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2024

Hi @Zoe Harris -- Welcome to the Atlassian Community!

First thing, this symptom appears to be a defect in the way automation rules handle list fields, like Fix Version, when using functions inside of iterators. 

There are similar community posts for the Sprint field.  If you are on a paid Jira license, I recommend working with your Jira Site Admin to submit a ticket to Atlassian Support so they are aware of it: https://support.atlassian.com/contact/#/  Make a copy of your original rule to provide to them context for the ticket.  When you hear back from them, please post what you learn to benefit the community.  Thanks!

 

Please note...complicated work-around ahead!

One complicated work-around, which is more challenging as you are trying to perform a diff() on two attributes of the field, forces the field list to split as you expect.  If you want to try one possible approach, these assumptions apply:

  • all of the issues in the Lookup Issues result must have a Fix Version assigned
  • all of the assigned Fix Versions must have values for Start Date and Release Date

If those match your case, you could try this expression.

{{#lookupIssues}} ticket key: {{key}}, start date: {{fixVersions.first.startDate.format("dd/MM/yyyy")}}, release date: {{fixVersions.first.releaseDate.format("dd/MM/yyyy")}}, difference between start date and release date: {{#=}}
( {{#fixVersions.releaseDate.join("~~").split("~~").first.toDate}}func=plusSeconds(0), format="toMillis"{{/}} -
{{#fixVersions.startDate.join("~~").split("~~").first.toDate}}func=plusSeconds(0), format="toMillis"{{/}}
) / (24*60*60*1000)
{{/}} days; {{/}}

How that works...

  • same iteration logic as you used for Lookup Issues to get the key, start date, and release date
  • however we observed the wrong dates from the list were selected for the diff, so let's force that to work...
    • first we grab a date value (e.g., releaseDate) and force it into a text string with join("~~")
    • then we use split("~~") to convert back into a list
    • grabbing the first item
    • and converting the text back into a date type with toDate
  • next we build our own version of the diff() function to subtract the two dates...
    • this expression will return the UNIX Timestamp in milliseconds for a date
      • {{#someDate}}func=plusSeconds(0), format="toMillis"{{/}}
    • if we subtract the value for the startDate from the releaseDate, we have a difference in milliseconds
    • which we can then divide by the number of milliseconds in a day: 24*60*60*1000
    • all of that is wrapped in a math expression

 

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events