How to add custom fields to email notification to specific issue type

ypertsov July 12, 2019

Hi, 

I have the following case:

I have configured 6 custom issue types custom issue field. Custom field "System" is present in 3 issue types. This custom issue field I need to add in email html notification. 

It's ok when issue screen has this custom field, its added correctly in email.

But in case if custom field is not on screens of issue type, I got this line in email:

System: $issue.getCustomFieldValue("customfield_10204")

I have used: Adding custom fields to email instruction with little changes.

https://developer.atlassian.com/server/jira/platform/adding-custom-fields-to-email/

Bellow here system.vm field description.

#disable_html_escaping()
#set ($customfield = $customFieldManager.getCustomFieldObject("customfield_10204"))
#if($issue.getCustomFieldValue($customfield))
<tr>
<th>#text($customfield.name):</th>
<td class="has-icon">
<th>$stringUtils.leftPad($issue.getCustomField("customfield_10204").name, $padSize):</th>
<td>$issue.getCustomFieldValue("customfield_10204")</a></td>
</td>
</tr>
#end

As I understood condition line #if($issue.getCustomFieldValue($customfield)) is incorrect ore doesn't work.

What is the better way to fix it?

2 answers

1 accepted

1 vote
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2019

Hello @ypertsov 

Please see this link

https://community.atlassian.com/t5/Answers-Developer-Questions/Add-custom-field-value-to-filtersubscription-vm/qaq-p/546214

You have to use "set" to set the custom field value and then later you can refer to it.

#set ($cf = $customFieldManager.getCustomFieldObject('customfield_10301'))
#set ($cfValue = $cf.getValue($issue))
cost center: $cfValue
ypertsov July 12, 2019

Hello @Tarun Sapra 

It was not full answer, but big help. 

Finally I made it this way:

#disable_html_escaping()

#set ($cf = $customFieldManager.getCustomFieldObject("customfield_10204"))

#set ($customfieldvalue = $cf.getValue($issue))

#if($customfieldvalue)

<tr>

<th>#text($cf.name):</th>

<th>$customfield</th>

</tr>

#end

After that, no error field in email anymore.

Tahnks.

 

May be do you know, how can I get translated value of custom field to  email?

0 votes
Andrew
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 12, 2019

Hi @ypertsov ,

<tr> - string in table

   <th></th> 

    <td> 

         <th> </th> - head inside cell? 

           <td></a></td>-where open tag a? Cell inside cell?

    </td> 

</tr>

Not sure that problem in tags, but try repair it.

B.R.

ypertsov July 12, 2019

Андрей, thanks, but no. Problem was in a condition

Suggest an answer

Log in or Sign up to answer