I have a requirement to extract the value present in a custom field of type "Version Picker" .
If I do this
def releaseVerField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_19641")
def releaseVerFieldValue = issue.getCustomFieldValue(releaseVerField).toString()
I get the output as [7.2] with square brackets. Can someone please advise how to get only the value and ignore the brackets.
The [] are a string representation of the fact you've got an list of somethings back from the field, not a string.
Version pickers can hold many options, so your getCustomFieldValue is getting a list (often it'll be a list of one item), then just using "toString" outputs a converted value.
You should not convert it, but iterate over the values and use .getName() or whatever you need to pull out the data you're looking for. If you can be absolutely sure it's only going to have one value, then just grab the first element from the list.
Hey @Nic Brough -Adaptavist-, I'm looking to do just this. Can you give an example of it. If I use this:
issue.get("customfield_10002")*.name.flatten()
I get the value with brackets. There will always only be one value here, how can I iterate just the value using getName?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If it always has one value only, you can be lazy. Issue.get("customfield_10002")[0] will fetch the first element of the array.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nic Brough -Adaptavist- Thanks for getting back to me, so I gave Issue.get("customfield_10002")[0] a try and it returns this:
CustomerOrganizationImpl{id=159, name=some company name}
I'm trying to get the name value without brackets. It appears the first element contains both the id and name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Adding a reply to @David
As I had the same issue and found a way to achieve it, though i was looking for the ID not the name.
change: value.id
to: value.name
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10110));
def OrgID = value.id[0]
log.info("OrgID:" + OrgID)
return OrgID
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.