Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Insert custom field in custom email body

Aravindi Amarasinghe
Contributor
July 24, 2018

Hi All, 

I want to send a customized email during the transition. 

I was using following code for the same reason in JIRA v 6.3 and it was working properly. 

<% out << (issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Test Phase"))).toString() %> - <% out << (issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("Client"))).toString() %> 

 

but when I try the same in JIRA 7.3.8 , Script Runner 5.0.11 it gives me following error when validating the code. Can someone help me to sort out this issue? 

Error

No such property: componentManager for class: groovy.lang.Binding

3 answers

1 accepted

0 votes
Answer accepted
Aravindi Amarasinghe
Contributor
July 31, 2018

Thanks all for the support. :) 

Following code worked for me. I added  com.atlassian.jira.component in front of the ComponentAccessor            

Test Phase: <% out << (issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Test Phase')).toString()) %>
0 votes
Neta Elyakim
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.
July 26, 2018

See jamie echlin- 

https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/33030148/Built-In+Scripts#Built-InScripts-Sendacustomemail

 

An email template example:

Dear <% out << issue.assignee?.displayName %>,  

The $issue.issueType.name $issue.key with priority <% out << issue.priority?.name %> has been assigned to you.  

Description: ${issue.description} 
<% if (lastComment)    
out << "Last comment: " << lastComment
%>
Custom field value: <% out << issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObjectByName("MySelect")) %> 

Regards,

<% out << issue.reporter?.displayName %>
Aravindi Amarasinghe
Contributor
July 31, 2018

Thanks Neta. Yeah I tried this code but it didn't work for me. 

0 votes
Mark Markov
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.
July 24, 2018

Hello @Aravindi Amarasinghe

You must use ComponentAccessor instead of componentManager.

Try this

<% out << (issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test Phase"))).toString() %> - <% out << (issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Client"))).toString() %>
Aravindi Amarasinghe
Contributor
July 25, 2018

Hi @Mark Markov 

Thank you for the answer. But it keeps throwing me this error 

No such property: ComponentAccessor for class: groovy.lang.Binding

And I tried this code suggested in other ticket. And it just print the same code in the email body. 

&lt;% out &lt;&lt; issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Client")) %&gt;
Mark Markov
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.
July 26, 2018

Hmmm, it should work.

Then try to pass value via config variable. Like in this example

In my opinion this is much better way to make email templates, because it is not that ugly :)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events