Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I create an email notification every time an issue is labeled or unlabeled?

I would like to create an email notification that is triggered every time an issue is labeled or unlabeled with a specific label. I've attempted to and don't believe this can be achieved with out of the box notifications with Jira. I also don't want to use a post function because I don't want the trigger dependent on a transition. Will I need to write some custom groovy? Is there an out of the box listener that exists for this already? Thanks in advance.

1 answer

0 votes
Ravi Sagar Community Leader Oct 15, 2019

Hi @Matt Marino 

What you can do is use the following code in Send a custom email listener's Condition and Configuration section.

Label added

import com.atlassian.jira.component.ComponentAccessor

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():""
if (previousLabels == "" && newLabels == "") {
//No existing labels
return false
}
else if (newLabels.indexOf("LABEL") == -1) {
//Label removed
return false
}
else if (previousLabels.indexOf("LABEL") == -1 && newLabels.indexOf("LABEL") > -1) {
//Label added
return true
}

Label removed

import com.atlassian.jira.component.ComponentAccessor

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():""
if (previousLabels == "" && newLabels == "") {
//No existing labels
return false
}
else if (newLabels.indexOf("LABEL") == -1) {
//Label removed
return true
}
else if (previousLabels.indexOf("LABEL") == -1 && newLabels.indexOf("LABEL") > -1) {
//Label added
return false
}

You can create two listeners - one for label added and the other one for label removed.

Let me know if this works.

Ravi

That worked! The email isn't firing every time, but that is a separate problem for me to resolve. Thank you for your help!

Like Ravi Sagar likes this

@Ravi Sagar Let me know if this is the wrong forum for this followup. I've got the custom emails set up with above code above (adjusted for my custom label) in the Condition and Configuration, and have tried using All Issue Events, Generic Events, and Issue Updated as which events to fire on. Instead of sending an email only when the label is added or removed, it's seemingly firing on almost every update to issues. Any insight?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

94 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you