Add custom field to JIRA e-mails

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

This widget could not be displayed.

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

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

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!

glad i could help...

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

Cheers Christian

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;

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")

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.

This widget could not be displayed.

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

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

$issue.getCustomFieldValue($fieldname)

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

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

34 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you