i am trying to pull updated date field value if my issue status is closed.
want to show in the scripted field.
Below code only gives the diff from created date that also not in number.
import com.atlassian.core.util.DateUtils import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.history.ChangeItemBean def componentManager = ComponentManager.getInstance() def changeHistoryManager = componentManager.getChangeHistoryManager() def inProgressName = "In Progress" def rt = [0] changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item -> def timeDiff = System.currentTimeMillis() - item.created.getTime() if (item.fromString == inProgressName) { rt << -timeDiff } if (item.toString == inProgressName){ rt << timeDiff } } // NOTE: doesn't show anything if less than 60 seconds DateUtils.getDurationString(Math.round(rt.sum() / 1000))
If you just want the date an issue was closed
item.created gives you the timestamp of when that history entry.
You also are not checking what that actual status so it loops though each status until it gets to the first history entry. To get the most recent CLOSED status..
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.changehistory.ChangeHistoryManager MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZAA-2"); ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager(); def X = changeHistoryManager.getChangeItemsForField (issue, "status") for (item in X?.reverse()) { if(item.getToString() == 'Closed') {log.error("X = ${item.getToString()} .. ${item.created} ${item.created.getDateString()}"); break;} }
logs X = Closed 2014-08-29 08:21:59.0 .. 8/29/14
For here you can do want ever calculation you want if you were looking to calculate say "issue has been closed for XXX days"
Thanks.. i did not understand the part of ZAA-2 as issue object. it should be dynamic. and is it possible to return the values to another custom field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ya sorry, I use that in scriptrunner to pull one of my test issues so that I can test a piece of code to make sure I am not writing junk code in an answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note that you should use issue.getCreated(), not issue.created. Because it clashes with issue.isCreated(), which is taken in preference when you use the property access format.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add: .format("MMM dd yyyy") or whatever
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.changehistory.ChangeHistoryManager MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("ZAA-2"); ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager(); def X = changeHistoryManager.getChangeItemsForField (issue, "status") for (item in X?.reverse()) { if(item.getToString() == 'Closed') {log.error("X = ${item.getToString()} .. ${item.created} ${item.created.getDateString().format("MMM dd yyyy")}"); break;} }
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.