Forums

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

How do I send an email notification on removal of a label?

Liam Page _EXT_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 2, 2021

I'm trying to make the removal of a certain label fire off an event to have an email being sent to a few people on the team, is there a way to do this? 

1 answer

1 accepted

Liam Page _EXT_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 9, 2021

I do appreciate the response, but one way or another that solution did not work, I did however get it to work using this chunk of code, for future people having the same issue.

import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor

def log = Logger.getLogger("com.acme.workflows")
log.setLevel(Level.DEBUG)
log.info("test message from matt")

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def previousLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getFromString(): ""
def newLabels = changeHistoryManager.getChangeItemsForField(issue, "labels") ? changeHistoryManager.getChangeItemsForField(issue, "labels").last().getToString():""

log.info("previousLabels : "+previousLabels)
log.info("newLabels : "+newLabels)

if (previousLabels != "" && previousLabels.indexOf("test") > -1) {
log.info("used to have it...")
if (newLabels == "" || newLabels.indexOf("test") == -1) {
log.info("and now gone...returning true get email")
return true
} else {
log.info("and still does")
}
} else {
log.info("didnt have it before")
}
log.info("returning false, no email")
return false

Suggest an answer

Log in or Sign up to answer