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 votes
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,120 views 13 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot