Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Date calculation in Jira automation

Hello Community!
I'm trying to do a date calculation in a Jira automation for the first time, but I'm not being able to get it right, so I'd like to see if anyone here has already gone through the same and could give me a hand =)
I'm trying to calculate the difference between to dates that are stored in different custom fields, and store the result of the math in a third custom field. I'm using the action "Edit issue fields" and, so far, the expression I came up with is the following:
{{issue.fields.Acceptance date.diff(issue.fields.Lead time start).days}}
The bolded strings in the expression are the custom date fields I'd like to calculate the difference.

3 answers

1 accepted

3 votes
Answer accepted

I wonder if you used the customfield ID would it make a difference? Replace the Xs with the field ID number.

{{issue.fields.customfield_xxxx.diff(issue.fields.customfield_xxxx).days}}

Thanks for the help Tim!! Would you be able to help me with where to find the customfield ID?

If you go to settings --> Issues --> Custom Fields. You can search for the custom field. Once you find the custom field you should see 3 dots, click on this then hover over edit and you will see a URL on the bottom of your browser and at the end of the URL you should see the ID. Something like below:

customfields.png

Like Fenner Matheus likes this
3 votes
John Funk Community Leader Jan 10, 2022

Hi @Fenner Matheus  - Welcome to the Atlassian Community!

Try this: {{issue.Acceptance date.diff(issue.Lead time start).days}}

Thanks for helping me out, John!! I have implemented your suggestion and it let's me publish the automation, but it doesn't update the field =(

John Funk Community Leader Jan 10, 2022

Can you share a screenshot of the audit log when you run it?

In this automation I also populate a different field with the current date, and this action is working fine...just the date diff that isn't =(

Snap9.jpgSnap8.jpg

John Funk Community Leader Jan 10, 2022

And what value does it put in the Lead time field? Just nothing? 

Also, but custom fields are the same type of date fields?

The suggestion below given by Tim helped me get it to work. Thanks also for your help, John!!

0 votes

Hello @Fenner Matheus ,

I know this question is focused on configuring automation rules but it looks like you are trying to calculate a Lead Time metric. I can offer another way that is much easier, more flexible, and more powerful.

 

Our team at OBSS built Time in Status app for these kinds of reporting. It is available for Jira Server, Cloud, and Data Center. 

Time in Status allows you to see how much time each issue spent on each status and on each assignee. 

tisCloud_StatusDuration_LeadTime_with Estimates.png  tisCloud_AssigneeDuration.png     

The app has Consolidated Columns feature. This feature allows you to combine the duration for multiple statuses into a single column and exclude unwanted ones. It is perfect to get measurements like Issue Age, Cycle Time, Lead Time, Resolution Time etc.

It is worth noting here that the app calculates its reports using already existing Jira issue histories so when you install the app, you don't need to add anything to your issue workflows or set any automation rules. You can get reports on your past issues as well. It supports both Company Managed and Team Managed projects.

For all numeric report types, you can calculate averages and sums of those durations grouped by the issue fields you select. For example total in-progress time per customer (organization) or average resolution time per week, month, issuetype, request type, etc. The ability to group by parts of dates (year, month, week, day, hour) is particularly useful here since it allows you to compare different time periods or see the trend.

tisCloud_StatusDuration_LeadTime_Average_TimeGrouped.png

Time in Status reports can be accessed through its own reporting page, dashboard gadgets, and issue view screen tabs. All these options can provide both calculated data tables and charts.

And the app has a REST API so you can get the reports from Jira UI or via REST.

Gadget_AverageStatusDurationByComponent.png  tisCloud_StatusDuration_LeadTime_Chart.png

Using Time in Status you can:

  • See how much time each issue spent on each status, assignee, user group and also see dates of status transitions.
  • Calculate averages and sums of those durations grouped by issue fields you select. (For example, see average InProgress time per project and per issue type.)
  • Export your data as XLS, XLSX, or CSV.
  • Access data via REST API. (for integrations)
  • Visualize data with various chart types.
  • See Time in Status reports on Jira Dashboard gadgets

https://marketplace.atlassian.com/apps/1211756/

EmreT

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
Community showcase
Published in Jira Software

👋 Looking for 15-20 volunteers to test Atlassian training content

Hi everyone! Are you interested in beta testing Atlassian University’s newest (unreleased!) training course? We’re looking for 15-20 volunteers to test our newest training course, Basic reporting...

883 views 25 28
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you