Forums

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

Cannot transition workflow during event listener on Issue Created

Code Different
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 1, 2020

I use the following snippet of code to automatically close an issue when it meets some conditions:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl

int transitionId = 31
def issueManager = ComponentAccessor.getIssueManager()
def util = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
def mutableIssue = issueManager.getIssueObject(issue.getKey())

util.setIssue(mutableIssue)
util.setUserkey("admin@company.com")
util.setAction(transitionId)
util.progress(

I put in a custom Event Listener script. The snippet does not work when the event is Issue Created. It reports no error, just does not change the status into the one I specified. If I change the event to Issue Assigned or Issue Commented, it works as expected.

Is Issue Created fired before or after the issue was actually created in Jira?

1 answer

0 votes
Subrat Mishra
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.
July 5, 2020

I hope your workflow triggers a "Issue Created" event upon creation , If not please check it in the workflow post-function section .

 

Also , you could try below script with some validation/logging enabled .

 

 

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.IssueInputParametersImpl

IssueManager issueManager = ComponentAccessor.issueManager
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
// Test with a single issue on script console, enable below line
// Issue issue = issueManager.getIssueObject("JIRA-1")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueService issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
def transitionOptions= new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

int actionId = 31

def transitionValidationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters,transitionOptions)


if (transitionValidationResult.isValid()) {
    def transitionResult = issueService.transition(user, 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")
}

Suggest an answer

Log in or Sign up to answer