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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

How to define a status in custom script field

Hi everyone,

 

i want to calculate age of issue and have script like that:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager

def issueManager = ComponentAccessor.getIssueManager()

if (issue.status.name == "RESOLVED" && "FAILED" && "CLOSED"){
return (issue.getResolutionDate() - issue.created)*24*60*60
} else {
return (new Date()- issue.created)*24*60*60
}

it calculate great age of opened issue, but i can't calculate age of closed issue, i mean how long was this issue active.

btw. i have 3 fields with Date: Created, Updatet and Resolved. Updated - Created works, Resolved - created not.

I try to define issue status in order for the script to understand in which case to calculate and than date of resolved issue subtract from issue created. 

How can i define my status and issue.resolved than subtract it? 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Andrei Lavrinovich 

We need some clarification.

First of all, the code snippet has some mistakes.

1. issue's status cannot be RESOLVED, FAILED and CLOSED at the same time, so you should change that as below

if (["RESOLVED", "FAILED", "CLOSED"].contains(issue.status.name){
return (issue.getResolutionDate() - issue.created)*24*60*60
}

However, as far as I see, you want to get resolution date if the issue was resolved. So, code below returns time passed till resolution field was changed.

if (null != issue.resolution) {
return (issue.getResolutionDate() - issue.created)*24*60*60
}

2. The next problem is to get the closed date. As far as I understand you want to calculate time between created till the issue's status changes as CLOSED. Unfortunately, Jira does not give that value out-of-the-box. You have to find it programatically or you need to use an app.

Below code gives you the date that issue was closed.

def changeHistoryManager = componentManager.getChangeHistoryManager()
def closedDate = changeHistoryManager.getChangeItemsForField(issue, "status").find{it.equals("CLOSED")}?.created

On the other hand, you can also use an app to get those values without bothering with scripts.

Enhancer Plugin has Time Between custom field, in which you can easily find time passed between any statuses or events. Please note that, I'm one of the folks behind Snapbytes, and there might be other solutions on Atlassian Marketplace as well.

I hope I was helpful.

Please let me know if I could not understand your question clearly.

Tuncay

Suggest an answer

Log in or Sign up to answer
TAGS

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