Send email from custom event

I have configured an Escalation Server to dispatch a custom event to the issues return from JQL filter. The custom event generated is used to Send a custom email from ScriptRunner Listeners.

When the filter results is just one issue, everything works fine. When the filter results are two or more issues, the emails are sent two e-mails from de same issue.

  • Escalation Service - Addtional issue actions
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.event.type.EventType;
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventDispatcher;

enableCache = {-> false};
IssueEventManager issueEventManager = ComponentAccessor.getIssueEventManager();
User usuario = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
EventType event = ComponentManager.getInstance().getEventTypeManager().getEventType(10100);
issueEventManager.dispatchEvent(event.getId(), issue, usuario, true);
  • Script Listeners - Send a custom email
    • Event: "Vencimento das ARPs" (custom event 10100)
    • E-mail template: 

      <p>Prezado(a) Senhor(a) Gestor(a): <% out << (cfValues['Gestor'] ? cfValues['Gestor']?.displayName : "-" ) %>,</p>
      <br />
      <p> A Ata de Registro de Preços abaixo irá vencer <font color="red"><b><% out << (cfValues['Vigência da Ata'] ? (((cfValues['Vigência da Ata']-new Date())/30).toLong() > 1 ? "em "+((cfValues['Vigência da Ata']-new Date())/30).toLong()+" meses" :  ((cfValues['Vigência da Ata']-new Date())/30).toLong() == 1 ? "em "+((cfValues['Vigência da Ata']-new Date())/30).toLong() + " mês" : ((cfValues['Vigência da Ata']-new Date())).toLong() > 0 ? "em "+((cfValues['Vigência da Ata']-new Date())).toLong() + " dia(s)" : "HOJE" ) : "-" )%></b></font>:
      <p><b>Número da ARP:</b> <% out << (cfValues['Número da ARP'].value ? cfValues['Número da ARP'].value : "-" ) %></p> 
      <p><b>Objeto:</b> <% out << (cfValues['Objeto'] ? cfValues['Objeto'].value : "-" ) %></p>
      <p><b>Contratada:</b> <% out << (cfValues['Contratada'] ? cfValues['Contratada'].value : "-" ) %></p>
      <p><b>Data de Assinatura/Emissão:</b> <% out << (cfValues['Data de Assinatura/Emissão'] ? cfValues['Data de Assinatura/Emissão'].format("dd/MM/yyyy") : "-" ) %></p>
      <p><b>Vigência da Ata:</b> <% out << (cfValues['Vigência da Ata'] ? cfValues['Vigência da Ata'].format("dd/MM/yyyy") : "-" ) %></p>
      <p><b>Pendência:</b> <a href=$issue.key>$issue.key</a></p>
      <br >

After execute the Escalation Service the result is:

Number of issues returned by query: 2
Issue CONTRATSTI-121 updated (no action defined)
Issue CONTRATSTI-96 updated (no action defined)

The events are generated and emails are sent. But i receive two emails from issue CONTRATSTI-96 e none from issue CONTRATSTI-121.

  • Jira Version: 6.3.1
  • Script Runner Version: 3.1.4

Thank you for your help in advance!

5 answers

Hi Robert,

The bad news, or good news, depending on your perspective, is that @Thanos Batagiannis [Adaptavist] told me he tried the following two scenarios:

  • raising an event in code as you are doing
  • transitioning the issue through an action that raises the event

Neither way worked properly with SR 3.1, producing the same results as you have seen.

Both ways worked properly on SR latest. 

You could always try an eval of SR latest to test if that fixes it, and you can revert to your current version afterwards if you want.


Hi Roberto, I tried to reproduce your problem and I couldn't for SR4. I will try again using SR3.1 and I will come back to you. PS. Can I ask you why you add an 'additional issue action' in the escalation service rather than just choose as action your custom action ? (I don't claim that this is the fix but, unless you want more than one action to happen in your escalation service, you add unnecessary complexity)

Hi @Thanos Batagiannis [Adaptavist], I've used the "additional issue action" because i haven't the action to dispatch this custom event in my workflow. I don't want to create a new transition to send the email, because i don't want a user to click in that transition. The issue itself represents an contract agreement that is current valid. The custom email will be send six, three and one month before its expires to warn the assignee to renew the contract agreement. Thanks.

Hi Roberto, Oh yes I see, in that case you are right. Thanks

Thanks a lot @Jamie Echlin [Adaptavist] and @Thanos Batagiannis [Adaptavist]. I've tried the evaluation version, but did not work.

I used the suggestion from Thanos and create a workflow transition that send the custom e-mail and configured the workflow condition to only execute from admin user and configure this user in the Escalation Service to execute de transition on the issues return from JQL.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


261 views 0 6
Read article

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