Getting an Event Name via Groovy

Normann P_ Nielsen _Netic_
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.
June 27, 2019

I am putting all Events into splunk:

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/event/issue/IssueEvent.html

Incuding the EventTypeId. But I cant get a hand on the Name itself like "Issue Created" - only by hardcoding it with if/case like:

 

if (EventId == EventType.ISSUE_WORKLOG_DELETED_ID)
{
EventName="Worklog Deleted"
}
if (EventId == EventType.ISSUE_WORKLOG_UPDATED_ID)
{
EventName="Worklog Updated"
}

How do I get hold of the name (also for Custom Events):

if (EventId == 10009)
{
EventName="P1 Incident"
}
if (EventId == 10010)
{
EventName="P2 Incident"
}

 

2 answers

1 accepted

3 votes
Answer accepted
fjodors
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.
June 28, 2019

Hi

I think you could get them from EventTypeManager, see code:

 

import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.type.EventTypeManager
import com.atlassian.jira.component.ComponentAccessor
EventTypeManager etm = ComponentAccessor.getEventTypeManager();

Collection<EventType> alleventTypes = etm.getEventTypes()

def result="";
for (EventType ev : alleventTypes) {
result+=ev.toString()+"<br>";

}

return result;
0 votes
Heiko Gerlach July 6, 2023

Hi, I recommend using the method 

 

EventType evtType=etm.getEventType(event.getEventTypeId())
instead. As a result you will get the Name by e.g.
log.warn("evtType="+evtType.name)
Cheers
Heiko

Suggest an answer

Log in or Sign up to answer