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

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

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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

23,675 views 2 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you