hi,
I was trying to calculate cycle time (time since) of issue in the current state using the below code.
It is not giving consistent results.
Don't know why
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def currentTime = System.currentTimeMillis()
def stateTime = 0
def items = changeHistoryManager.getChangeItemsForField (issue, "status").reverse()
if (items) {
stateTime = items.first().created.time
}
else {
stateTime = issue.getCreated().time
}
def stateCycleTime = (currentTime - stateTime) / (1000*60*60*24)
return (stateCycleTime as Double).round(2) ;
Can any one help in understanding the problem and a good fix
can you please check the below code which works as "Minutes in Particular Status" and change accordingly to days?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def status_Name= "status_name"
List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
item.toString == inProgressName
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == status_Name) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}
def total = rt.sum() as Long
log.warn("Total Time "+total)
total = (total/(1000*60))
return total ?: 0L
Thanks @Sai Ram Kumar Singarapu
After debugging I found that "System.currentTimeMillis()" is not consistent.
Not sure why
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can try getting curretn date in mili sec by `new Date().getTime()`
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi, I tried with scripted custom field just with this line
return new Date();
the result is in-consistent
Do you have any clue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Rajesh Asana
I suggest you take a look at the original Timepiece - Time in Status for Jira by OBSS. Our app does exactly what you need.
I know you want to achieve this via custom code rather than an app but believe me, buying our stable app will save you time and money.
We now have Server, Data Center and Cloud options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Rajesh Asana
You can get a good fix for this problem by using additional plugins instead of doing it manually with code.
For instance, you can use Time in Status for Jira Cloud by SaaSJet (you can get it from Atlassian Marketplace). This add-on helps you to easily and automatically calculate the time of issue in the current state.
Also, you can try Time Between Statuses for calculation status to status time. This app help you to get the Cycle and Lead Time of your Jira issues
Data from two these add-ons are available for export as XLSX or CSV file.
Hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply,
My intention was not to add plugin as I want to build my rule of my own.
Could you help me understand the problem behind the code which gives an in- consistent behavior of the return value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.