Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Add Custom Field Value to Email Template

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

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

 

please attach both files..

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

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

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

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

 

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

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 Steven McCaffrey likes this

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
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,917 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you