Groovy listener: copy component's description to custom field.

Hi!

I have some question about groovy and jira. I want to copy component's description to custom field, if this component was chosen.

How can I get current component's description?

2 answers

1 accepted

1 vote
Henning Tietgens Community Champion Dec 17, 2013

To get the current components descriptions as a comma separated list you can write

String componentsDescriptions = issue.componentObjects*.description.join(',')

Tarun Sapra Community Champion Feb 11, 2014

Hi Henning, how to null check it, if it's being used part of gStringTemplate engine

would the below work?

${issue.componentObjects*?.description.join(',')}

Henning Tietgens Community Champion Feb 11, 2014

I don't think that you have to null check, if you use the *. operator. Did you have any problems?

Tarun Sapra Community Champion Feb 12, 2014

Hi henning,

Iam using this expression as part of the email template using script runner built-in post function to send custom email

${issue.componentObjects*.name.join(',')} but it's not getting the component names.

Henning Tietgens Community Champion Feb 12, 2014

Did you tried

<% out << issue.componentObjects*.name.join(',') %>

like shown in the example in the script runner docs?

Tarun Sapra Community Champion Feb 13, 2014

Hi Henning, Thanks it works now! :) but why was it not working with ${} and works with <%out %>

Tarun Sapra Community Champion Feb 13, 2014

is it because ${} is used only to show data already there in the bean and <% %> is used for minupulation/evaluation of data

Henning Tietgens Community Champion Feb 13, 2014

I think it has something to do with the point in time when the expressions are evaluated. But I'm not sure.

I don't know groovy syntax but I have posted Java coding here. You can interpret in to groovy.

import com.atlassian.jira.bc.project.component.ProjectComponent;

String compDescr="";
for(ProjectComponent comp : issue.getComponentObjects())
{	
	compDescr = compDescr +comp.getDescription()+"\n";
}
CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager();
issue.setCustomFieldValue(cfm.getCustomFieldObjectByName("&lt;your customfield name&gt;"),compDescr);
// The issue should be mutable issue and imagining the customfield is of text type

JiraAuthenticationContext authContext=ComponentAccessor.getJiraAuthenticationContext();

ComponentAccessor.getIssueManager().updateIssue(authContext.getLoggedInUser(),issue,EventDispatchOption.ISSUE_UPDATED,false);

ComponentAccessor.getIssueIndexManager().reIndex(issue);

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

134 views 0 3
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