Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Script Field to Calculate Age of Issue (Jira Cloud)


Hi all,

I'm migrating Jira to the Cloud and I had a calculated field from Jira Misc Tools Add On. Because this Add on does not exist in the Cloud, I'm trying to use Script Runner to do the same.

The code that I had in the Jira Misc Calculated field was:

issue.get("updated")==null ? null : ((new Date().getTime()) - issue.get("updated").getTime()) / 1000 / 3600

Can you help me converting it to be used as a script listener or scripted field? 

Thanks in advance,


2 answers

Meanwhile I found a way to do it

import java.sql.Timestamp
import java.time.*
import java.text.SimpleDateFormat
import java.text.DateFormat
import java.util.Date
import java.util.concurrent.TimeUnit

def issueKey = 'SomeIssue'
def updated = "updated"
long ElapsedDays = 0
def today = new Date()

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");

def getresult = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
if (getresult.status == 200){
    updated = getresult.body.fields[updated]
    if (updated != null) {
        Date updated_date = sdf.parse(updated.toString());
        ElapsedDays = (today - updated_date) // return days
        return ElapsedDays
} else {
    return "Failed to find issue: Status: ${getresult.status} ${getresult.body}"

0 votes

Hello Hugo,

I know you are asking about a Script Runner field but you may want to change it to a ready-made solution that offers much more features and flexibility.


Our team at OBSS built Time in Status for this exact need. It is available for Jira Server, Cloud, and Data Center. 

Time in Status basically allows you to see how much time each issue spent on each status and on each assignee. You can see this data in the app's main reporting page, Time in Status tab on issue view pages and also dashboard gadgets.

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 the most flexible way to get any measurement you might want. Measurements like Issue Age, Cycle Time, Lead Time, Resolution Time etc.

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.


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 and you can get reports on your past issues as well. It supports both Company Managed and Team Managed projects.

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


Suggest an answer

Log in or Sign up to answer

Atlassian Community Events