Originally asked by Mouna Hammoudi on 05 April 2022 (original question)
I would like to write some code to check if an issue has been exalated in scriptrunner, I am using the following code in scriptrunner for the scripted field that I created as a custom field but it seems that I have a compilation error: I am getting the error stating that [Static type checking] - The variable [eventTypeManager] is undeclared. I am importing the appropriate packages though, how can I fix this problem. Otherwise, how can we check in scriptrunner that and issue has been exalated?
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventType
import com.atlassian.jira.event.type.EventTypeManager
import com.atlassian.jira.*
import com.atlassian.jira.component.pico.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class DefaultAccountListener extends AbstractIssueEventListener {
private final Logger LOG = LoggerFactory.getLogger(DefaultAccountListener)
private static final String EXALATED_EVENT_TYPE = "com.exalate.api.domain.trigger.EXALATED"
private static final String EXALATE_UPDATED_EVENT_TYPE = "com.exalate.api.domain.trigger.UPDATED"
@Override
void customEvent(IssueEvent event) {
Issue issue = event.issue
EventType eventType = eventTypeManager.getEventType(event.getEventTypeId())
LOG.debug("Custom event caught for issue ${issue.key}: type [${eventType.type}], name [${eventType.name}], nameKey [${eventType.nameKey}]")
if (eventType.name.equalsIgnoreCase(EXALATED_EVENT_TYPE)) {
LOG.debug("EXALATED event caught for issue ${issue.key}")
}
}
}
Comments:
Francis Martens (Exalate) commented on 06 April 2022
eventTypeManager needs to be instantiated.
Check componentAccessor for more details.
Mouna Hammoudi commented on 06 April 2022
I used the code which instantiates EventTypeManager and I get the error Cannot find matching method com.atlassian.jira.event.type.EventTypeManager#getEventType(java.lang.Object). Please check if the declared type is correct and if the method exists
EventTypeManager eventTypeManager=ComponentAccessor.getEventTypeManager()
EventType eventType = eventTypeManager.getEventType(event.getEventTypeId())
if (eventType.name.equalsIgnoreCase(EXALATED_EVENT_TYPE)) {
return “EXALATED event caught for issue ${issue.key}”
}