Scripted Field - Need to return only toString Value, not entire string

AndreH April 25, 2014

I have a scripted field that only needs to return the toString value. Instead it returns the entire string value.

Here is the Script -

import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()

def changeHistoryManager = componentManager.getChangeHistoryManager()

x = changeHistoryManager.getChangeItemsForField(issue, "Root Cause Primary")

if (x.join(' ') == "") {

return null

}

return x.join(' ')

When I run a preview it returns this string -

com.atlassian.jira.issue.history.ChangeItemBean@xxxxxxx[fieldType=custom,field=Root Cause Primary,from=,fromString=,to=1000005,toString=Business Configuration Data,created=2013-10-11 11:24:56.0]

How do I get it to return only the toString=Business Configuration Data?

The field should only show - Business Configuration Data

Thanks,

Andre

1 answer

1 accepted

1 vote
Answer accepted
Boris Georgiev _Appfire_
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.
April 25, 2014

You need to transform the collection of ChangeItemBean objects to collection of String.

Here's the code:

import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()

def changeHistoryManager = componentManager.getChangeHistoryManager()

x = changeHistoryManager.getChangeItemsForField(issue, "Root Cause Primary").collect { it.toString }

if (x.join(' ') == "") {

return null

}

return x.join(' ')

Suggest an answer

Log in or Sign up to answer