Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help With Groovy Script Field

Kumar
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.
December 12, 2018

Hi Team,

Here I'm creating a script fields

> The  total Time Status in Particular Status. here is the script Can any one help in my script that its calcualting the Milleseconds I need like proper Time Format and days.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inProgressName = "X"

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName) {
rt << timeDiff
}
}

def total = rt.sum() as Long
return (total / 1000 ) as long ?: 0L

Its counting in total seconds 

Is there any chance to count  if the ticket is been in that status like 7 days  in that particular ticket so that i can add that in column report.

can any one suggest me please.

 

thanks,

Kumar

 

1 answer

1 accepted

0 votes
Answer accepted
Jenna Davis
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.
December 12, 2018

Hello, 

You should simply need to modify the in the last line of your code that is converting milliseconds (the original format you get) to seconds so that it is converting milliseconds to days. For example, the 1000 you're currently using is because there are 1000 milliseconds in a second. You need to get milliseconds in a day. If you do the time calculations (or look it up), you can find that there are 86400000 milliseconds in one day. Thus, to get days from this you need to change the last line of your script to 'total/86400000'. 

Hopefully this helps! Let me know if you have any other questions.  

Jenna 

Kumar
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.
December 12, 2018

Hi @Jenna Davis Thanks for your response

It worked it calculate days i'm asking like format like 

"07days  | 02:30m "

 Like kind of format if I want how can I modify this can you help me or if i want to know 

When I Open any issue if want to know how many days since its been in that status need to know do i need to create each status script field ???

 

Thanks,

Kumar

Jenna Davis
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.
December 12, 2018

Okay, I think this community post might help you out:

https://community.atlassian.com/t5/Marketplace-Apps-questions/Age-of-the-Issue/qaq-p/275028

In short, try using 'DateUtils.getDurationString()' method. That post shows you what is needed in a bit more detail. 

Jenna

Kumar
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.
December 12, 2018

Hi @Jenna Davis thanks for your reply

 

I just need to know the total days and Time spent on particular status on each issue.

Example:

On "X"  status the issue is been like 1d 2h 30m 

like on each status how much time spent a user i need to know

the link you shared is calculating an total issue time that will help me in one but now i'm looking like on each status how much time it spent 

 

Thanks,

Kumar

Jenna Davis
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.
December 12, 2018

You should be able to do this using the example in the link I sent, you just need to modify the code a bit based on what you want to get. 

For example:

DateUtils.getDurationString((total / 1000) as Long)

 Does this make sense?

If you're getting back something different that what you expect when you try this could you please let me know what template you're using and what exactly gets displayed?

Jenna

Kumar
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.
December 12, 2018

Hi @Jenna Davis  Thanks for your help it worked 

here is the Final script

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.core.util.DateUtils

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inProgressName = "X" // put status that you want

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName) {
rt << timeDiff
}
}

def total = rt.sum() as Long
return DateUtils.getDurationString ((total / 1000) as Long) ?: 0t

 

 

Thanks,

Kumar

Kumar
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.
December 13, 2018

Hi @Jenna Davis  

If I want get the "assignee" info in those status how can i modify the script

can you help me  please with the above script that it also need to pull the "Assignee" in those particular status.

Thanks,

Kumar

Suggest an answer

Log in or Sign up to answer