Need a misc calculated field that shows Components of an issue as a String

Hi All,

I've just started using EazyBI and I'm adding some extra fields to it using the MISC custom fields add-in. 

So far so good for most simple things I need, however I am now trying a more complex field to store all Components selected on an issue into a separate custom text field as a comma delimitted string.

I just can't seem to get the right syntax or I'm missing something obvious.

On the EazyBI website I can see this example for Fix Versions:

<!-- @@Formula:
import org.apache.commons.lang.StringUtils;
StringUtils.join(issue.get("fixVersions"), ",");
-->

This works great for that field. I then tried issue.get("components") but that didn't work for me.

Looking through the API knowledge base for Components it seems I need to use issue.getComponents() to return a collection and then .getName() to return the name part of the collection? 

Anyone know a simple way to grab all the names of the selected components and put them into a string? 

Any help is much appreciated!

 

1 answer

1 accepted

1 vote
Accepted answer
Gaston Valente Community Champion Jul 19, 2017

Hi Gareth,

I'm sure there're better and more clean ways, but this should work:

<!-- @@Formula:

import com.atlassian.jira.bc.project.component.ProjectComponent;
import java.lang.StringBuffer;

StringBuffer issueComponents = new StringBuffer();

for(ProjectComponent pc : issue.get("components")){
if(issueComponents.length() > 0) issueComponents.append(",");
issueComponents.append(pc.getName());
}

issueComponents.toString();
-->

Thanks this works perfectly!

Gaston Valente Community Champion Jul 23, 2017

great!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

415 views 0 3
Read article

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