Add custom field to JIRA e-mails

Georgiy Senenkov December 4, 2012

Hello,

I would like to add custom field to JIRA 5.1 html notifications e-mail. I found that I need to modify velocity templates , e.g. issuecreated.vm. In that file i found references to the include folder to specify which fields to include.

Could you please advise how to make .vm file for custom field to include it into issuecreated.vm?

Thank you in advance.

Regards, Georgiy

2 answers

1 accepted

2 votes
Answer accepted
C_ Faysal
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.
December 4, 2012

hi

lets assume your customfield has id 11800

in your your_new.vm file put this info:

#disable_html_escaping()
#if ($issue.getCustomFieldValue("customfield_11800"))
<tr valign="top">
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;">
        <strong style="font-weight:normal;color:${textSubtleColour};">#text("NAME OF YOUR FIELD"):</strong>
    </td>
    <td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;">
        $issue.getCustomFieldValue("customfield_11800")
    </td>
#end
</tr>

then include it in issuecreated.vm like this:

#if ($issue.getCustomFieldValue("customfield_11800"))
$stringUtils.leftPad($issue.getCustomField("customfield_11800").name, $padSize): $issue.getCustomFieldValue("customfield_11800")
#end

C_ Faysal
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.
December 4, 2012

this will make your field appear in emails only if it has values...

Like Carolina Rodrigues likes this
Georgiy Senenkov December 4, 2012

I made new.vm file as you advised and then included it into issuecreated.vm file as

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

and it works as needed :)

Thank you very much!

C_ Faysal
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.
December 4, 2012

glad i could help...

Christian Czaia _Decadis AG_
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.
May 28, 2013

Shouldn't the closing</tr> tag be positioned before the #end

Cheers Christian
C_ Faysal
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.
May 28, 2013

oh you're right. just for optical satisfaction...but it works like this (i took it from current working instance)

ok i just re-checked with an out-of-the-box file that came with jira..

cat atlassian-jira/WEB-INF/classes/templates/email/html/includes/fields/reporter.vm

#disable_html_escaping()
&lt;tr valign="top"&gt;
    &lt;td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 10px 10px 0;white-space:nowrap;"&gt;
        &lt;strong style="font-weight:normal;color:${textSubtleColour};"&gt;#text("issue.field.reporter"):&lt;/strong&gt;
    &lt;/td&gt;
    &lt;td style="color:${textColour};font-family:${textFontFamily};font-size:${textSize};padding:0 0 10px 0;width:100%;"&gt;
        #if ($issue.reporterId)
            #authorlinkkey($issue.reporterId $linkstyle)
        #else
            #text("common.concepts.no.reporter")
        #end
    &lt;/td&gt;
&lt;/tr&gt;

Will November 21, 2015

I am encountering a problem with including custom fields in e-mail templates. The template does not appear to evaluate the getCustomFieldValue it simply output the raw code, see below. The custom field has a value for the issue I am sending the e-mail from. Is there a setting or other action needed to get the custom fields to work or is my code wrong? Any advice is appreciated. I am running JIRA 6.3.15 Code in template file: #if ($issue.getCustomFieldValue("customfield_10011")) $stringUtils.leftPad($issue.getCustomFieldObjectByName("customfield_10011").name, $padSize): $issue.getCustomFieldValue("customfield_10011") #end Participant: $issue.getCustomFieldValue("customfield_10011") Result in e-mail: Participant: $issue.getCustomFieldValue("customfield_10011")

pokalav May 11, 2017

Hi Faysal,

     As you mentioned first, In which folder could i past that code can you clarify that i need priority_Hcp customfield is to add in email.

 

Thank you,

Venkatesh.

1 vote
Sreenivasaraju P
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.
December 4, 2012

You can create your own vm or templates,you can refer custom fields as below.

#set($fieldname=$customFieldManager.getCustomFieldObject("customfield_11100"))

$issue.getCustomFieldValue($fieldname)

Sameera Shaakunthala [inactive]
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.
April 3, 2013

Is the following syntax OK?

#set($cf_downtime=$customFieldManager.getCustomFieldObjectsByName("Downtime").next())

$issue.getCustomFieldValue($cf_downtime)

Basically what I'm asking is, can we use getCustomFieldObjectsByName() function?

Suggest an answer

Log in or Sign up to answer