Forums

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

Listener seems to be picking up update event, but not create event

Chris P_ April 10, 2020

1st Post!

So I've written a listener that I've got working on update events, but refuses to fire when on the initial issue creation.

The listener is intended to pick up on issues that don't have certain values set or are missing information and stick them into a Triage status. Once the tickets are in a good state after editing, the tickets go back to an open state.

I'd like to be able to expand on this listener over time to include more auto-transition scenarios, but need to be sure it works first in this simple Triage case.

My suspicion is the workflow isn't firing the event for whatever reason.

 

Hope the community can help me solve this, thanks!

 

Setup

In Listeners Section:

- Events Enabled: Issue Created, Issue Updated

Workflows:

On Create => Open, Fire a Issue Created event that can be processed by the listeners.

 

 

Script (works when editing): 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject(event.issue.key)
IssueService issueService = ComponentAccessor.getIssueService()
def actionId = 221 // change this to the step that you want the issues to be transitioned to
def actionId2 = 251 // change this to the step that you want the issues to be transitioned to
def transitionValidationResult
def transitionResult
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def resultfield = customFieldManager.getCustomFieldObjectByName("Result")
def resultfieldvalue = issue.getCustomFieldValue(resultfield).toString()

log.debug("The issue type is: " + issue.getIssueType().name)

if (issue.priority?.name != 'Not Set' && issue.status?.name == 'Triage') { // Looks for all issues that are ready to go out of triage

transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId2,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
else {
log.debug("The transitionValidation is not valid")
}
}

if (issue.getIssueType().name == "Bug" && issue.priority?.name == 'Not Set' && resultfieldvalue != null) { // looks for all bugs that need to go into triage

transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId,new IssueInputParametersImpl())

if (transitionValidationResult.isValid()) {
transitionResult = issueService.transition(currentUser, transitionValidationResult)
if (transitionResult.isValid())
{ log.debug("Transitioned issue $issue through action $actionId") }
else
{ log.debug("Transition result is not valid") }
}
else {
log.debug("The transitionValidation is not valid")
}
}

 

1 answer

0 votes
Chris P_ April 10, 2020

Suggest an answer

Log in or Sign up to answer