Add Custom Field Value to Email Template

Christina Hiller July 22, 2019

I'm trying to add a custom field value to the create issue HTML email template, but stumbling.  The field is required, so there will always be a value present on issue creation.

Attempt 1:

I've followed the directions here: https://developer.atlassian.com/server/jira/platform/adding-custom-fields-to-email/?_ga=2.56485292.608403254.1563807890-1574526416.1556543036

When I add the customerfield.vm as indicated below

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#if($issue.getCustomFieldValue($customfield))
<tr>
    <th>#text($customfield.name):</th>
    <td class="has-icon">      
        $textutils.htmlEncode($issue.getCustomFieldValue($customfield), false)
    </td>
</tr>
#end

 

Instead of the comma separated values of the field, I get this message: $textutils.htmlEncode($issue.getCustomFieldValue($customfield), false) attempt 1_JIRA instruction.png

Attempt 2:

I tried the suggestion in another article, but instead of the value, I get the label name a second time.

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#set ($customfieldvalue = $customfield.getValue($issue))
#if($customfieldvalue)
<tr>
<th>#text($customfield.name):</th>
<th>$customfield</th>
</tr>
#end

and tried

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#set ($customfieldvalue = $customfield.getValue($issue))
#if($customfieldvalue)
<tr>
<th>#text($customfield.name):</th>
<th>$customfieldvalue</th>
</tr>
#end

attempt 2_community suggestion.png

 

 

I can't tell if my issue is coming from the createissue.vm or customfield.vm or how to fix it.  any help/suggestions would be very much appreciated!

1 answer

1 accepted

0 votes
Answer accepted
Manuel Bastardo Castellano
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 22, 2019

Hello @Christina Hiller do you create the customfield.vm and add this to the event createissue.vm?

 

please attach both files..

Christina Hiller July 22, 2019

I'm having trouble attaching the files themselves, but here's the content.

 

createissue.vm

#disable_html_escaping()

#defaultMailHeader("email.event.activity.created.issue", $issue.reporter)

#set ($issueTitleBody="#parse('templates/email/html/includes/patterns/issue-title.vm')")

#rowWrapperNormal($issueTitleBody)
#rowWrapperNormalBegin('' 'wrapper-special-margin')

<table class="keyvalue-table">
#parse("templates/email/html/includes/fields/issuetype.vm")
#parse("templates/email/html/includes/fields/affectsversions.vm")
#parse("templates/email/html/includes/fields/assignee.vm")
#parse("templates/email/html/includes/fields/attachments.vm")
#parse("templates/email/html/includes/fields/components.vm")
#parse("templates/email/html/includes/fields/createddate.vm")
#parse("templates/email/html/includes/fields/duedate.vm")
#parse("templates/email/html/includes/fields/environment.vm")
#parse("templates/email/html/includes/fields/fixversions.vm")
#parse("templates/email/html/includes/fields/labels.vm")
#parse("templates/email/html/includes/fields/priority.vm")
#parse("templates/email/html/includes/fields/reporter.vm")
#parse("templates/email/html/includes/fields/securitylevel.vm")
#parse("templates/email/html/includes/fields/timetracking.vm") #parse("templates/email/html/includes/fields/customfield.vm")

</table>

</br>
#rowWrapperNormalEnd()


#if ($issue.description)
#set($textParagraph = $issue.htmlDescription)
#rowWrapperNormal("#parse('templates/email/html/includes/patterns/text-paragraph.vm')", '', 'issue-description-container')
#end

#set ($commentActionBody="#parse('templates/email/html/includes/patterns/comment-action.vm')")
#rowWrapperNormal($commentActionBody)

#parse("templates/email/html/includes/footer.vm")

 

latest customfield.vm

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#set ($customfieldvalue = $customfield.getValue($issue))
#if($customfieldvalue)
<tr>
<th>#text($customfield.name):</th>
<th>$customfieldvalue</th>
</tr>
#end
Manuel Bastardo Castellano
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 22, 2019

Try with this 

customfield.vm

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#if($issue.getCustomFieldValue($customfield))
<tr>
<th>#text($customfield.name):</th>
<td class="has-icon">
$textutils.htmlEncode($issue.getCustomFieldValue($customfield), false)
</td>
</tr>
#end

don´t forget restart jira

Christina Hiller July 24, 2019

2019-07-24_11-48-29.pngHi Manuel

Using the code provided, above screen is what comes through.

 

Christina Hiller July 24, 2019

Another question I have is if I expect that multiple values are expected in the custom field results, would that result in an error?

Christina Hiller July 24, 2019

I replaced the customfield.vm file with the following and it worked.

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_15707"))
#if($issue.getCustomFieldValue($customfield))
<tr>
<th>#text($customfield.name):</th>
<td class="has-icon">
$customFieldManager.getCustomFieldObject("customfield_15707").getValue($issue)
</td>
</tr>
#end
Like # people like this
Manuel Bastardo Castellano
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, 2019

i was already trying :) 

Captura de pantalla 2019-07-24 a las 18.35.36.png

Suggest an answer

Log in or Sign up to answer