Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Emailing during transition

Jeff Coulter March 2, 2020

I have a field called "Escalated to Teams".  This field is pre-populated with a value during an earlier transition.  Later on in the workflow, this field appears on a screen during a transition and is changed by the user to a new value.  Based on the value selected, I want an email sent to people associated with that value.

What I did was set up several listeners using scriptrunner.  I chose the Send a Custom Email listener type and set the Events to Issue Updated.

The Condition and Configuration looks like this:

import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Escalated to Teams") // name of CF

def optionsManager = ComponentAccessor.getOptionsManager()

def fieldConfig = customField.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find { it.value == "Dreamworks" } // value of option

def change = event?.getChangeLog().getRelated("ChildChangeItem").find {it.field == "Escalated to Teams"}

if (change) {
if (issue.getCustomFieldValue(customField) == option) {
log.debug("Found the correct option")
return true
}
}

I then set up an email template and subject template. 

However, no email is being triggered during the transition.  The transition validates the Escalated to Teams field is required.  The Post Functions include that a generic event is fired.  The only other thing I can think of is that I have a second scriptrunner "Send a custom email" set up that fires first.  This second scriptrunner email isn't based off of any condition or configuration and just notifies different managers of the change in status.

However, if I simply edit that field without transitioning the issue, the email does fire. 

1 answer

1 accepted

1 vote
Answer accepted
Tanya Gordon
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.
March 2, 2020

Hi Jeff,

This happens because the listeners aren't triggered during the transition because there's no Issue Updated event fired for it.

As far as I could understand you have set up several listeners, one per team, and you validate the team name in the condition to know where to send the email, correct?

I would suggest the following changes:

  1. create custom events based on the Issue Updated event (gg -> events --> go to the bottom of the page and simply add a new event that's based on Issue Updated event). Create an event per team.
  2. Update the listeners to listen to the new event/s (each listener will be triggered by a specific team's update event)
  3. Update the transition post function to fire your new events. Use scripted post function to analyze the change and fire the relevant event.
    1. In case you're unable to retrieve the change element you could try the following:
      1. Sleep for several seconds and try again. Do it only if running in a separate thread
      2. Analyze the history and calculate the change yourself. 

That way you won't get the email in case there was a regular issue update without a transition, because the listeners will be triggered only by your custom events.

 

Let me know what you think and if any help is needed.

Tanya

Jeff Coulter March 2, 2020

Thanks Tanya!  Actually, I didn't do quite what you said, but when you mentioned the reason is that no Issue Updated event was fired for it, that made me think I should change the type of event in the workflow that was fired.  I just changed it from Generic Event to Issue Updated event and then the listeners would pick it up.  That seemed to work. 

I do realize that if those fields are changed at any time, without a transition, the email will fire, but I think that's ok for our purposes.  I appreciate your help!

Tanya Gordon
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.
March 2, 2020

Great!

If you need anymore assistance in the future, don't hesitate to ask :-)

Suggest an answer

Log in or Sign up to answer