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

Kate December 17, 2013

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
Answer accepted
Henning Tietgens
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.
December 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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
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.
February 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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
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.
February 12, 2014

Did you tried

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

like shown in the example in the script runner docs?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 13, 2014

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 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
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.
February 13, 2014

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

0 votes
Bharadwaj Jannu
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.
December 17, 2013

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