Unable to shoot email notification from Custom Velocity Template

ashygoyal January 5, 2016

Case: Created a custom .vm template, added it as an event in JIRA. But its not working.

Steps followed:

  1. Created a mytemplate.vm file, each in HTML, TEXT and SUBJECT directories in this path (based on other files in these directories): …\atlassian-jira\WEB-INF\classes\templates\email\
  2. Added the mytemplate.vm to atlassian-jira\WEB-INF\classes\email-template-id-mappings.xml to make it a valid choice for when I’ll be adding a new event. Restarted JIRA service.
  3. Added it as an event in JIRA. Restarted JIRA service again. Now mytemplate reflects in notification scheme.
  4. Added that notification scheme to a sample project.

 

mytemplate.vm contains logic to shoot an email when a new issue is created. Basically just a copy of default issuecreated.vm, but with a different name. Just to see, if custom .vm template can also send an email notification.

In my notification scheme, I disabled the by default issuecreated.vm file for JIRA. Now my custom template must fire an email on issuecreate event. The problem is, when I create an issue, no email notification is being sent from JIRA.

Also note, SMTP configuration is working fine, because I am receiving email notifications on issueassigned, issuecommented, etc

I have checked the JIRA logs too, in order to find any error or deviation from normal behavior, but couldn’t see anything unusual. It would be very helpful, if anyone can provide any pointers in this regard.

Thanks,

Ashish

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Maitrey Patel
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 3, 2019

What I am doing wrong here or missing?

 

I am creating a custom event with custom templates.

  • Created a custom template and added to right directories for text, HTML & subject with same names.
  • Created a custom event with ID 10500. I have updated my mapping file like this: <templatemapping id="10500">
  • <name>Ratings On Resolve</name>
    <template>issueresolvedRatings.vm</template>
    <templatetype>issueevent</templatetype>
    </templatemapping>
  • Mapped proper template with event.
  • Updated event with the new template. 
  • Then I updated the notification scheme to send it to the reporter.
  • Updated workflow to change "Generic Event" to new event.

Still, I am not getting email notifications. What I am doing wrong here? 

I would like to meet you guys in Summit @ Las Vegas.

0 votes
Nic Brough -Adaptavist-
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.
January 5, 2016

This sounds a bit confused.  An email template .vm is NOT an event, and it does not contain code to send emails off.

Events are fired inside JIRA.  If there's a listener or other code listening for an event, that can do something with it.  The standard built-in function is the notification scheme stuff.  When that picks up an event, it reads the project notification scheme, and then builds an email with the appropriate users listed, and with content determined by the templates, and then it sends it.

The templates have nothing to do with the events directly.

JIRA is still firing "issue created" events.  The question to my mind, is that after all your changes, what template is being used for "issue created"?  Forget your new events, what template is used for the issue created event?

ashygoyal January 5, 2016

Hey, hello Nic, Sorry if my explanation leaded to confusion, I think I can explain it in more detail. It goes like this: I copied content of .../html/issuecreated.vm -> pasted it in .../html/mytemplate.vm I copied content of .../text/issuecreated.vm -> pasted it in .../text/mytemplate.vm I copied content of .../subject/issuecreated.vm -> pasted it in .../subject/mytemplate.vm Next step, I added below lines in ...\atlassian-jira\WEB-INF\classes\email-template-id-mappings.xml : <templatemapping id="18"> <name>My Custom Template</name> <template>mytemplate.vm</template> <templatetype>issueevent</templatetype> </templatemapping> Next step, I went to JIRA > System > Events : Selected 'Add New Event', gave, Name- My Custom Event from Template dropdown, i selected: 'My Custom Template'. Then clicked on 'Add'. Then, I created a notification scheme: My Custom Notification Scheme I added notifications for all JIRA defined events (except Issue Created) like Issue Updated, Issue Assigned, Issue Resolved, etc.(the notification was that an Administrator of a particular Project will get email). In the same list of events, last event was - My Custom Event. To this event too, i added the same notification that if fired, it should send an email to project's admin. Then I attached this notification scheme to the concerned JIRA Project. So, now when a new Issue is created in that project, no email is being sent. Although 'My Custom Event', which should ideally send a mail on issue creation (since it has the same code/content of issue created event), no mail is being sent from JIRA.

Nic Brough -Adaptavist-
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.
January 5, 2016

No, you're misunderstanding the whole system. Your custom event is all fine for adding a new event and getting a different email out. But that has nothing to do with "issue created". You say "should send a mail on issue creation since it has the same code as issue created". That's wrong. As I said before, the templates are templates for building emails. They have nothing to do with with the events. Issue creation fires the event "issue created". You've created "my custom event" and "template used by my custom event". You have set up any form of relationship between issue creation and your event (let alone template)

ashygoyal January 5, 2016

Oh, got your point. Please correct me if I'm wrong. 1. I should create a relationship between my custom event and the 'issue creation' action, (if i dont want to disturb JIRA's by-default issue created template). or 1. Do you mean that I cant create a whole new template for issue creation, since JIRA already has a by default template for issue creation. I can only add custom fields to the already existing .vm files. Is that the case? Also, can you share your email id if possible? I may require your help going forward in this regard. Thank you, Ashish (goyal.ashish3@gmail.com)

Nic Brough -Adaptavist-
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.
January 6, 2016

I think you have understood it now. The problem with "create a relationship" for the create issue action is that it's all hard-coded in the core of JIRA. Your custom event is irrelevant, the "create issue" action will always fire "issue created" unless you hack the core (which I can not recommend) The better option is to amend the templates for the "create issue" action

ashygoyal January 6, 2016

Thanks a lot Nic for this clarification, saved me from wasting any further time on it. But to be true, why I started moving into this direction was, because my requirement is to send an email notification (with particular custom content) from JIRA, when a particular transition happens in a workflow (say, for example, when the transition moves from Testing to Deployed), keeping in mind, that I should not disturb the already existing JIRA .vm files. The reason being, there are many different teams using the same JIRA, all of them have different projects in JIRA. So playing with existing JIRA velocity templates, will affect all other projects in JIRA. As per our discussion on this page, what I infer is that the only way is to modify 'issueupdated' velocity template, since transition change in workflow will ultimately update the status in an issue. Any pointers/ help on how to achieve the requirement, it would be of great great help. Thanks again.

ashygoyal January 6, 2016

I think I just got my answer while doing some R&D! I attached my 'custom template' to a 'custom event' in JIRA. Then associated that 'custom event', as a post function to that particular transition on which I want to fire a custom email and this is working like a charm now! I'll elaborate it separately in my answer to this post!

Nic Brough -Adaptavist-
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.
January 7, 2016

Ahh, yes, I concentrated on the "issue create" because that is a *system* event, not a workflow event, and you can't change that without core coding. Workflow events are completely customisable - you can fire any event you want at the end of a transition, and hence tie your changes into it.

TAGS
AUG Leaders

Atlassian Community Events