Get Component Value not as string in Groovy

Cailin Che April 25, 2024

I'm working on an HTML notification template (in JEMH) that uses Groovy. I'm trying to pull the component value as just the name so that we can include it as part of the email. That way the user who is notified has a nice little summary. We have a working template, but we recently adjusted the way we use the tickets and moved the old custom field into the unused Component field.

Here's my snippet to call the field in the email template.

<td>
#if ($!issue.getComponents())
<b>Organization:</b>
$issue.getComponents()
#end

 

The problem is that this returns a whole string about the component, as below:

[ProjectComponentImpl { name='Component Name Here', description='', lead='fqi1', assigneeType='1', projectId='13700', id='27933', archived='false', deleted='false' }]

 

I need it to display just the name (Component Name Here) instead of the whole string. I have been scouring the web, but haven't found anything that will display just the name. I should mention that the entire extent of my groovy knowledge is adjusting these templates that were built by other people. Is there something I'm missing? This is the only version of getting the component that returns ANYTHING, I've tried all kinds of variations, especially with Value or Val thrown in there.

 

Thanks in advance!

2 answers

1 accepted

1 vote
Answer accepted
Ryan Clifton April 26, 2024

Hello @Cailin Che,

Currently, the Components field can contain multiple values. Due to this it results in "$issue.getComponents()" returning a json array with all of the relevant information for each component value (e.g. description, projectId ...etc).

Due to this, to gather the name of each component you would need to use a foreach loop to iterate over each value that "$issue.getComponents()" returns and then use getName() to get the name for each component.

For a brief example on this see Components on the following page: Customize Email templates

If you require any further assistance with this, then feel free to contact The Plugin People Support, by either emailing support@thepluginpeople.com or by using our Support Portal

 

Kind Regards,

Ryan (The Plugin People Support)

Cailin Che April 26, 2024

Thanks @Ryan Clifton !

This example is shorting out my template. I will submit a ticket.

Cailin Che April 26, 2024

Turns out if you don't forget the second #end tag, it works like a charm...

Thanks Ryan!

0 votes
Dave Rosenlund
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 25, 2024

Hi, @Cailin Che.  With only 2K installs across Data Center and Cloud, I'm not sure there are enough Enterprise Mail Handler for Jira (JEMH) [by The Plugin People] here on the community for you to get a quick response.

If I were you, I'd go directly to the source and contact their support team.

Assuming you do—and another community member doesn't provide an answer here—let us all know what the issue was and how it was solved.

That way, others will benefit from reading about the resolution here in the future.

Good luck,

-dave

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events