Trying to fix a really old scripted field for time between statuses. I'm not at this level of complexity (I just did an Age field, but it took a lot of trial and error). Any ideas where line 16 went wrong? I am getting Static Type Checking error on L16,C17 for cannot cast java.sql.Timestamp to double and doulbe#minus(java.sql.Timestamp)
import com.atlassian.core.util.DateUtils import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.history.ChangeItemBean import com.atlassian.jira.issue.Issue def componentAccessor = ComponentAccessor def changeHistoryManager = componentAccessor.getChangeHistoryManager() def timediff = 0.0 ChangeItemBean item = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.toString == "Analysis Complete"} if( null != item ) { def To_Trans_time = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.toString == "Analysis Complete"}?.getCreated() ChangeItemBean item1 = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.fromString == "In Progress"} if( null != item1 ) { def from_Trans_time = changeHistoryManager.getChangeItemsForField(issue, "status").find {it.fromString == "In Progress"}?.getCreated() timediff = (double) To_Trans_time - from_Trans_time } }
Here is a draft for script to start. Main question is to define what to do if issue was into requred status more that once.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.changehistory.ChangeHistoryManager; import com.atlassian.jira.issue.history.ChangeItemBean import com.atlassian.jira.issue.Issue ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager() List<ChangeItemBean> items = changeHistoryManager.getChangeItemsForField(issue, "status").sort( //sort all new Comparator<ChangeItemBean>() { @Override int compare(ChangeItemBean o1, ChangeItemBean o2) { return o1.getCreated().after(o2.getCreated()) ? 1 :-1; } } ) if(items.size() == 0) //there were no status change at all return null //now we have all status chages sorted by time //some logic for all cases //code example to return value. It is requared to define do we return worjing or calendar days. It return total time in milliseconds return items.get(0).getCreated().getTime() - items.get(1).getCreated().getTime() //returns milliseconds
Thank you! We actually rarely have a return to Analysis Complete before In Progress, but I see what you're saying. I'll see what I can do with this and convert to answer if I can get it puzzled out.
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.