Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Catch "Issue Delete"/"Issue Move" events in scriptrunner listener

Edited

Hi all,

I'm trying to setup a scriptrunner listener that is linked to two types of issue events:

- Issue delete

- Issue move

When the event is caught, I want to send a notification in slack.

Problem is, I don't know how to distinguish between the two events within the same listener.

So far I had to split the listener and create one linked to delete event, and another one linked to move event. Both use an event of type "IssueEvent"

 


import com.onresolve.scriptrunner.slack.SlackUtil
import com.atlassian.jira.event.issue.IssueEvent
// what else should I import?

def myEventClassName = event.class
def myEntityName
def myEvent
def messageHeader1 = "<!here> *ISSUE DELETED WARNING:*\n"
def messageHeader2 = "<!here> *ISSUE MOVED WARNING:*\n"
def messageHeader

if(event instanceof IssueEvent){ // this where I need to catch the delete event
messageHeader = messageHeader1
myEvent = event as IssueEvent
myEntityName = myEvent.getIssue().getKey()
}
else { // this where I need to catch the move event
messageHeader = messageHeader2
// blah blah
}

SlackUtil.message(
"my_slack_connector",
"my_slack_notification_channel",
messageHeader+"\n"+myEventClassName+": "+myEntityName,
[
username: "My bot",
icon_emoji : ":myavatar"
]
)

 

1 answer

1 accepted

3 votes
Answer accepted

Hi @Guy Incognito

You can use this to catch the event type:

 

import com.atlassian.jira.component.ComponentAccessor

def eventTypeManager = ComponentAccessor.getEventTypeManager()
def eventTypeName = eventTypeManager.getEventType(event.eventTypeId).getName()
log.error("myEventTypeNameMOVED: "+ eventTypeName)

 

As I found you have to set the listener to global or you have to define all the project the issues can be moved to. I found that if I just set the listener to one project and I move the issue to another one, you won't catch the issue moved event, only if the listener is global or the target project is included either.

 

Hope this helps!

Hey @Miklos Tix ,

It worked like a charm, thanks a lot!!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events