Get value from Array List without brackets []

David May 20, 2019

I'm trying to get a value from the Organizations field in JSD without the brackets.

Using ${issue.get("customfield_10002")*.name.flatten()} will get me the organization name, but puts it in brackets. How do I get rid of those?

2 answers

1 accepted

1 vote
Answer accepted
Radhika Vijji _Innovalog_
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.
May 28, 2019

Hi David,

Try issue.getAsString("customfield_10002"). This returns a string representation of the value of issue field. Please check the Groovy console provided by the app. It has a help system with Groovy scripts showing how to access issue fields and much more.

Regards,

Radhika

David May 28, 2019

That just gives me the id of the organization and not the name.

For instance:

issue.get("customfield_10002")

Returns with this:

[CustomerOrganizationImpl{id=159, name=some company name}]

Where as:

 issue.getAsString("customfield_10002")

Returns with:

159

I'm trying to access the name part of this without brackets.

Radhika Vijji _Innovalog_
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.
May 28, 2019

Oh yeah. issue.get("customfield_10703")*.name.flatten() returns an array of Strings. Use the join operator to get just the name(s).

issue.get("customfield_10703")*.name.flatten().join(",")

Regards,

Radhika

David May 29, 2019

This solved it for me. Thank you!

1 vote
Payne
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.
May 20, 2019

One way is to use substrings; I use the following function in a script to accomplish this.

def stripBrackets(String str){
String retStr = str
if(str == null || str.length() < 2)
{
return str
}
if(retStr.substring(0,1).equals("[")){
retStr = retStr.substring(1)
}
if(retStr.substring(retStr.length()-1).equals("]")){
retStr = retStr.substring(0,retStr.length()-1)
}
return retStr
}
David May 28, 2019

@Payne thanks for getting back to me. I'm not sure how I would use that substrings script. I'm using the JMWE  plugin with groovy code.

${issue.get("customfield_10002")*.name.flatten()}  gets me a value that looks exactly like this with the brackets: [some organization name].

Do you know how I would be able to use the substrings in groovy code so the result of "getting" customfield_10002 is just "some organization name" with no brackets?

Suggest an answer

Log in or Sign up to answer