in jira custom_plugin scriptrunner sendemail ~ read.

How to send e-mail on custom field change in JIRA

Currently i'm working as a Test Lead in a new company and we started to move from Bugzilla to JIRA. So it appears, that we have some custom fields and we needed specific behaviour for them - in case when field gets set to "?" or some other value - specific people should be notified with custom e-mails. At first i thought that i could achieve this with Scriptrunner plugin where i would just

  • Install Script Runner plugin from Marketplace
  • Open workflow and click on transition or screen where i need to track field change
  • Click on Post-Function link
  • Select Script Post-Function
  • Click on "Send Custom e-mail"
  • Enter groovy script with condition description. To get value from custom field you need to use
cfValues['Custom field name']*.value.contains('value')
  • Note: this script depends on what type field are you using for custom field, so in case if it doesn't work - try different options here.
  • Email template example can look like this :
Dear <% out << issue.assignee?.displayName %>,
  
The $issue.issueType.name $issue.key with priority <% out <<

issue.priority?.name %> has been assigned to you.
  
Description: ${issue.description}
 
<% if (lastComment)
    out << "Last comment: " << lastComment
%>
 
Custom field value: <% out << issue.getCustomFieldValue(
componentManager.getCustomFieldManager()
.getCustomFieldObjectByName("MySelect")) %>
 
Regards,
<% out << issue.reporter?.displayName %>

This approach is pretty easy to implement, but there's one big disadvantage that made us to decline it:

  • Let's say that we created a ticket and set one of our custom fields to the value that passes post-script condition
  • E-mail get's sent to appropriate person
  • Not you edit this ticket again and do not change custom field
  • E-mail will be sent again to appropriate person, but we didn't want that

That why i decided to write a custom plugin for jira that will handle this situation properly. I will write how to setup project and write the plugin itself in the next articles.

comments powered by Disqus
comments powered by Disqus