I'm trying to create a scripted field to store the length of time that an issue was in a particular status. In this example, the status is "Acknowledged".
The error I'm getting is:"The indexer for this field expects a java.lang.Double but
the script returned a java.lang.String - this will cause problems."
Here is my script:
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 AcknowledgedName = "Acknowledged"
def rt = [0]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == AcknowledgedName) {
rt << -timeDiff
}
if (item.toString == AcknowledgedName){
rt << timeDiff
}
}
// NOTE: doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(rt.sum() / 1000))
I wish there was an easier way to do this. I can see exactly what I need on the Transitions tab per issue but I need to be able to get the information for multiple states and all issues.
Community moderators have prevented the ability to post new answers.
You have to change the search template of the custom field to "Free Text Searcher" and the Template to "Free Text Field (unlimited text)" if you want to display the duration as a String.
Henning
Thank you so much, it worked like a charm!
I also have a follow up question...Is it possible to calculate the minutes between two states instead of the duration in a particular state?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think it's all how you handle the changeHistory changeItems. If you search for the last change to "Acknowledged" and, as a second point in time, the next change of the status after this change, the difference would be the (last) time in "Acknowledged" status.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting The indexer for this field expects a java.lang.Double but the script returned a java.util.ArrayList when using Free Text Searcher.... how do I return a list?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the message you already return a list... if you use the free text searcher you should use Free Text Field, too. Then you could return your list as a String if you append a .toString() to the result. For further questions it would be easier if you would post you code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
.toString() worked fine, but now it is showing on screen when there is a null value
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.issue.Issue; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Verification Status") def value = issue.parentObject.getCustomFieldValue(field); if (field) { return value.toString(); } else { return null }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
// Only ComponentAccessor needs to be imported import com.atlassian.jira.component.ComponentAccessor; // Return value, if anything isn't working always return NULL def ret = null // get the customfield def field = ComponentAccessor.getCustomFieldManager()?.getCustomFieldObjectByName("Verification Status") // Make sure the customfield exists, otherwise we might get NullPointerExceptions if (field) { // Read the value from the parent issue in a safe way def value = issue?.parentObject?.getCustomFieldValue(field) // Only return the string if there is a value if (value) { ret = value.toString() } } return ret
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.