How to add additional fields to the email notifications?

Sebastian July 2, 2015

I would like to add additional fields (default fields in JIRA e.g Priority, Type) to the email notifications 'reopened issue'. How I can achieve this? Please advise

14 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Sebastian July 2, 2015

Hi Nic,

I added this statement:

#if ($issue.getPriorityObject() && $issue.getPriorityObject().getId() != $constantsManager.getDefaultPriority().getString("id"))
$stringUtils.leftPad($i18n.getText("issue.field.priority"), $padSize): ${issue.getPriorityObject().getNameTranslation($i18n)}
#end

to this dircetory \templates\email\text\issuereopened.vm, I restarted JIRA and still this field is not visible in the email notifications for me. Do I missed something?

 

Nic Brough -Adaptavist-
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 2, 2015

Does your workflow fire the "issue reopened" event, and is that event mapped to the "issue reopened" template? (Those are the defaults, so if you're using the JIRA workflow and haven't changed the config) Also, are you using text or html mail? That change should only affect the text email, so you need to ensure the text is there. Did you restart JIRA after the change? It caches stuff, including email templates sometimes. Finally, although I think your code looks correct at a glance, could you add a bit of debugging - literally drop in some plain text like "My fields should be next" on the line above the "if", so that we can see that we're getting the right email

2 votes
Nic Brough -Adaptavist-
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 2, 2015
Sebastian July 5, 2015

I added a line of text above #if block, reopened the issue in JIRA and I received default email notifiaction without priority field (please see attached file)

NotificationEmail.png

Nic Brough -Adaptavist-
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 5, 2015

Ah, you missed the point in my earlier comment. You have been editing the text vm file, and that is an html email. You need to either swap to text emails or go edit the html templates.

Sebastian July 5, 2015

So I need to edit and add this code under email/html/issuereopened.vm?

Like Tomáš Vošický likes this
Nic Brough -Adaptavist-
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 5, 2015

Yes, although with html email, you need to be a bit careful with the layout. If you get the text in the wrong place, it may appear in the wrong place, or not at all. (If in doubt, stick it in a <div>...</div> - that usually means it will at least get displayed)

Sebastian July 5, 2015

Nic, sorry for bothering you so many times, but I added this code below to the email template (html/issuereopenened.vm) and I did restart JIRA, reopened an issue and still I don't get in the email notification the field with priority. (I also tried stick this code in a <div>...</div>) issureopened.vm template view: #disable_html_escaping() asdasdasdasdasdasd #if ($issue.getPriorityObject() && $issue.getPriorityObject().getId() != $constantsManager.getDefaultPriority().getString("id")) $stringUtils.leftPad($i18n.getText("issue.field.priority"), $padSize): ${issue.getPriorityObject().getNameTranslation($i18n)} #end #genericChangelogMailWithComment("jira.email.title.issue.reopened")

Nic Brough -Adaptavist-
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 6, 2015

No problem. I assume that the asdas stuff is not coming out either? If not, then it implies that your workflow is not firing the event you need, and/or the event is mapped to the wrong email template, and/or your notification scheme does not link the event to the right email.

Sebastian July 6, 2015

Ok Nic, I fixed this issue. Thank you for your help.

1 vote
Sebastian July 22, 2015

Hi Nic,

I resolved this question, as first we need to use toString(). and then we can make the substring

 

Thank you for your help

Cheers

Nic Brough -Adaptavist-
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 22, 2015

Ah, glad you got there, despite my cack-handed coding! This is why I'm not allowed to be a developer... ;-)

Samuel August 26, 2016

Sebastian

can you please share your your code for priority? I am trying to make similar notification for updated issue but its not working for me. Thanks in advance

0 votes
Sebastian July 22, 2015

I tried use substring for custom value, but this is what I received in the email notification:

Image 1.png

0 votes
Sebastian July 22, 2015

I resolved one of the issue above, if you could just help me with those additional values in this new created custom ('data') field? (they are marked by red circle in above prt screen)

Nic Brough -Adaptavist-
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 22, 2015

Ah, yes, in the background, JIRA stores and retrieves both date and date/time fields in the same way - as a date and time. When the field is just a date, it whacks in "midnight" for the time. All the code that presents dates to the users looks at the field type and if it says "just a date" on it, it simply drops the time component. There's a few things you could do for a date field, but it might be easiest to use brute force in your template. Let's say you're using $issue.getCustomFieldValue("customfield_10201") to get that date string out. Try $issue.getCustomFieldValue("customfield_10201").substring(0,9) to yank out the first 10 characters.

0 votes
Sebastian July 22, 2015

Nic, forget the above questions. This one will be my last (I promise). Below you will find screen shot from new notification email which I recevied. I added new custom field (end data) which is data format field. Could you please tell me why the data format has some additional values at the end?

Image 1.png

$stringUtils.leftPad($issue.getCustomField("customfield_10201").name, $padSize): $issue.getCustomFieldValue("customfield_10201")

And if you could give me the advise how I can customize this field like the other fields/values? (e.g. Resoultion: Fixed - I mean here font-size, font-family etc)?

Many thanks,

Sebastian

Samuel August 31, 2016
    I just need to know how you displayed the "Priority" with Icon and matching text like other fields. Can you help?
    I am trying to display priority (same as other field) when issue is updated but it just show as plain text.
    Thx
0 votes
Sebastian July 21, 2015

Hi Nic,

thank you for your response, it's multi-select option. I added this code :'[1].getValue()' and below is te screen shot from mail notification which I received

Image 1.png

If I may ask about one more additional thing: is there any way to customize value from custom field like the other values? (e.g. Resoultion: Fixed - I mean here font-size, font-family etc)?

Sorry for bothering you.

0 votes
Nic Brough -Adaptavist-
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 21, 2015

Ahh, it's a multi-select.  Ok.  Try:

$issue.getCustomFieldValue("customfield_10100")[1].getValue()

0 votes
Sebastian July 21, 2015

I added getClass().toString() and I received this:

Image 1.png

0 votes
Sebastian July 21, 2015

No worries, I changed this to getValue(), and below is the prt screen with email notification which I received:Image 1.png

Nic Brough -Adaptavist-
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 21, 2015

Ok, what does just $issue.getCustomFieldValue("customfield_10100") do? Something is failing me on this and I can't see it. Oh, and also $issue.getCustomFieldValue("customfield_10100").getClass().toString()

0 votes
Sebastian July 21, 2015

Hi Nic,

thank you for the response, but unfortunately it does not work. Below you will find code which I changed:

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

 

This is the email confirmation which I get: any thoughts?

Image 1.png
Nic Brough -Adaptavist-
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 21, 2015

Bother. It is be getValue() rather than getName() Sorry about that, I get my field types mixed up a lot!

Nic Brough -Adaptavist-
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 21, 2015

"It is be"? The coffee can't have reached my grammar neurons. It is getValue()

0 votes
Sebastian July 20, 2015

Hi Nic,

below you will find code which I have in the email\html\issueresolved.vm template:

#disable_html_escaping()
#set ($resolution = "&lt;strong&gt;$textutils.htmlEncode(${issue.getResolutionObject().getNameTranslation($i18n)}, false)&lt;/strong&gt;")
#defaultMailHeaderWithParam("jira.email.title.issue.resolved", $changelogauthor, $resolution)
#if ($comment)
    #parse('templates/email/html/includes/patterns/comment-top.vm')
#end
#rowWrapperNormal("#parse('templates/email/html/includes/patterns/issue-title.vm')")
#if ($issue.getCustomFieldValue("customfield_10100"))
$stringUtils.leftPad($issue.getCustomField("customfield_10100").name, $padSize): $issue.getCustomFieldValue("customfield_10100")
#end
#if ($changelog)
    #rowWrapperNormal("#parse('templates/email/html/includes/fields/changelog.vm')")
#end
#set ($commentActionBody="#parse('templates/email/html/includes/patterns/comment-action.vm')")
#rowWrapperNormal($commentActionBody)

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

I am trying to display value from custom field, it is displaying the value correctly, but with some strange customization(please see attached file). Is there anything what can I do to display this value from custom field as other? (e.g. Change By)

Image 2.png

Nic Brough -Adaptavist-
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 20, 2015

I'm guessing that "sex" is a custom field with a select list? And you've done something like $issue.getCustomFieldValue(customfield("sex)) in the template? If that's true, it's because Jira has handed the velocity an "option" instead of a string and the [] are just saying "this is my best guess on how to display this". Try adding .getName() to the end - that should get the option represented as the string you've got in the name.

0 votes
Sebastian July 6, 2015

Just one more question abut this case. I received email notifications correctly with information about my custom fields, but I would like to move/insert data from custom field inside the 'table confirmation' (e.g after Status statement before add comment) please see attached file.

Image 2.png

Sebastian July 8, 2015

any updates on this, please

Sebastian July 10, 2015

Is there any chance to get some feedback/help from someone?

Nic Brough -Adaptavist-
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 10, 2015

Oops. My apologies... I remember typing an answer for this, but I suspect I wandered off or shut down before clicking "comment". Anyway, the gist of it was that you need to do one of three things. Look at issuesummary.vm - it's a block of code that is used by almost all the emails, so its standardised and changes will appear in all the issues. - if you want your data to appear on all emails, include it in the issuesummary file instead - if you only want your code on re-opened, then you could code it into issuesummary and surround it with #if (test for reopened) (your code) #end - it might be neater and clearer to drop the #parse issuesummary.vm line from re-opened and implement the parts you need from it manually in the reopened template (including your code)

0 votes
Sebastian July 2, 2015

I changed the default workflow so íssue reopened' is avaiable and I am getting an email notification. Also I put this code into the ''issue reopened'' template under the text email. I restart JIRA after change. Below you will find code which is currently in my email\text\''íssue reopened'' template.

#disable_html_escaping()
#parse("templates/email/includes/issueplugins.vm")
     [ ${baseurl}/browse/${issue.getKey()}?page=${tabpanel-all} ]
#headerTitleText($i18n.getText("template.issue.reopened.by", $remoteUser.displayName, $issue.key), $remoteUser.displayName)
#changes(["resolution"])
#comment()
#visibilityText()
#if ($issue.getPriorityObject() &amp;&amp; $issue.getPriorityObject().getId() != $constantsManager.getDefaultPriority().getString("id"))
$stringUtils.leftPad($i18n.getText("issue.field.priority"), $padSize): ${issue.getPriorityObject().getNameTranslation($i18n)}
#end
#parse("templates/email/text/includes/issuesummary.vm")
#parse("templates/email/text/includes/footer.vm")
Nic Brough -Adaptavist-
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 3, 2015

Ok, and what happens if you add a line of text above your #if block?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events