The following code and variations has been circulating around on how to calculate a time in the template "duration" format for an issue. I have the code working but I believe it is setup to calculate a cumulative total of any time the issue has been in a status during it's lifecycle.
I'm attempting to create a version of this code that will only show the current instance of being this status (any status). So for instance:
Here is the code being utilized:
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name
def rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt << -timeDiff
}
if (item.toString == currentStatusName){
rt << timeDiff
}
}
def total = rt.sum() as Long
return (total / 1000) as long ?: 0L
I would like this data to retain the duration template if at all possible.
My thought is I need to get the last status change time here somehow, and eliminate the second if statement?
Thank you in advance!
Hi @Bartosz Boratyński ,
Please try this script to update the field :
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), optionClone), new DefaultIssueChangeHolder())
To add a comment :
def commentManager = ComponentAccessor.getCommentManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def comment = "test"
def enableNotification = true
commentManager.create(issue, user, comment, enableNotification)
Antoine
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.