Transition on issue created event

Deleted user March 6, 2018

Is there any way to do this with script?

I am constantly getting error that it is not possible in the current state, even though I'm in the Open step. I have tried with reindexing issue after creation as well.

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issue = event.getIssue()
def reporter = issue.getReporter()

def upm = ComponentAccessor.getUserPropertyManager()


def propertySet = upm.getPropertySet(reporter)

if(propertySet.getString("jira.meta.Spam").equals("true")){
def workflowManager = ComponentAccessor.getWorkflowManager()
IssueService issueService = ComponentAccessor.getIssueService()
JiraWorkflow jiraWorkflow = workflowManager.getWorkflow(issue)
def issueIndexService = ComponentAccessor.getComponent(IssueIndexingService)
StepDescriptor oStep = jiraWorkflow.getLinkedStep(issue.getStatus());
List<ActionDescriptor> oActions = oStep.getActions();
for(ActionDescriptor oAction : oActions){
if(oAction.getName().equals("Spam")){
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
def validationResult = issueService.validateTransition(currentUser, (Long) issue.getId(), oAction.getId(), issueInputParameters)
log.warn validationResult.getErrorCollection()
if(validationResult.isValid()){
issueService.transition(currentUser,validationResult)
}
}
}
}

 This works well for issue updated event, just not on create.

2 answers

1 accepted

0 votes
Answer accepted
Deleted user March 6, 2018

I have managed to get the wanted functionality!

Instead of using custom made script, use fast-track transition an issue script.

in the end only code needed to accomplish the check is this 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserPropertyManager
def upm = ComponentAccessor.getUserPropertyManager()
def reporter = issue.getReporter()
def propertySet = upm.getPropertySet(reporter)
propertySet.getString("jira.meta.Spam").equals("true")

 I don't understand why this is not possible with regular script but hey! 

0 votes
Vasiliy Zverev
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.
March 6, 2018

Are you sure, that user is allowed to perform this transition?

You should check conditions and validators.

Deleted user March 6, 2018

Hi, 

yes this is my local testing JIRA, I am both administrator and service desk team, using the default permission scheme. 

There is nothing(validators,conditions) on the transition except one additional post function setting the resolution.

As I said, it is working fine on update, just not on create.

Darin Hafer November 28, 2023

I had the same exact issue. I wrote a listener that worked on Update but not on Create. Then I wrote a custom post-function and that does the same thing that a 'fast-track transition' does. My custom post-function returned error:

[It seems that you have tried to perform a workflow operation (<name of action>) that is not valid for the current state of this issue (ABC-123). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.] 

That isn't the likely cause at all. Whatever the cause, Deleted user is correct, it works when using an Adaptavist 'fast-track transition'.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events