Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

AndreH
Contributor
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
TAGS
atlassian, jira product discovery, product operations, product ops, linkedin live, atlassian events, cross-functional collaboration, product management, engineering collaboration, design collaboration, atlassian learning, agile teams, product strategy

Product Ops Unpacked: 4️⃣ tips every product pro needs to know ✍️

Join PM Evangelist, Axel Sooriah, & Product Ops. Consultant & Advisor, Jenny Wanger, as they unpack the role of product ops and discuss key takeaways in Atlassian’s ‘The Product Ops Mission’ guide. They’ll answer your questions live on May 6 at 9:00am PT.

Register here ⬇️
AUG Leaders

Atlassian Community Events