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, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events