Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

The indexer for this field expects a java.lang.Double but the script returned a java.lang.String - this will cause problems

Jeannette Lamb February 20, 2013

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.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 21, 2013

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

Jeannette Lamb February 21, 2013

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?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2013

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.

Kate McAnespie July 6, 2015

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?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 6, 2015

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.

Kate McAnespie July 7, 2015

.toString() worked fine, but now it is showing on screen when there is a null value

Kate McAnespie July 7, 2015

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 }

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 7, 2015

// 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

TAGS
AUG Leaders

Atlassian Community Events