Forums

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

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

Guy Incognito
Contributor
October 27, 2023 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

4 votes
Answer accepted
Miklos Tix
Contributor
October 27, 2023

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!

Guy Incognito
Contributor
October 27, 2023

Hey @Miklos Tix ,

It worked like a charm, thanks a lot!!

Suggest an answer

Log in or Sign up to answer