It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
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"
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;} }
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreAtlas Camp is our developer event which will take place in Barcelona, Spain from the 6th -7th of September . This is a great opportunity to meet other developers and get n...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.