Forums

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

ScriptRunner: Error:"you have tried to perform a workflow operation (TestStatus) that is not valid"

zaharovvv_suek_ru
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 8, 2018 edited

I run this script in the Script Console.

I am trying to set status for issue. I use "issueService.transition()" method for this purpose. 
The full code looks like this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.IssueManager

import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.ListLinks")
log.setLevel(Level.DEBUG)

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueManager = ComponentAccessor.issueManager
def issue = ComponentAccessor.getIssueManager().getIssueObject("EL-115")

def workflowManager = ComponentAccessor.getWorkflowManager()
def workflow = workflowManager.getWorkflow(issue);


def testTransitionId = 11;

def issueService = ComponentAccessor.getIssueService();
def issueInputParameters = issueService.newIssueInputParameters();


IssueService.TransitionValidationResult validationResult = issueService.validateTransition(currentUser, issue.id, testTransitionId as Integer, new IssueInputParametersImpl())
def errorCollection = validationResult.errorCollection

log.debug('transition section:')
if (! errorCollection.hasAnyErrors()) {
log.debug('transition section. Successful')
issueService.transition(currentUser, validationResult)
}
else {
log.debug('transition section. Something wrong here')
log.error(errorCollection)
}

However, I see the following error:


2018-06-08 18:15:04,294 ERROR [acme.ListLinks]: Errors: {}
Error Messages: [It seems that you have tried to perform a workflow operation (Test status) that is not valid for the current state of this issue (EL-115).
The likely cause is that somebody has changed the issue recently, please look at the issue history for details.]

Guys, what I can do to solve this error or how can set another status for issue using ScriptRunner?

 

My Workflow looks like this:

Workflow to be deleted.png

3 answers

2 accepted

1 vote
Answer accepted
Mark Markov
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 8, 2018

Does 11 transition can be performed from current status? and CurrentUser passes permisions and validators to do that transition?

zaharovvv_suek_ru
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 8, 2018

@Mark Markov yeah, I've used your code snippet to see possible transitions and verify possibility to go to "testTransition":

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.JiraWorkflow
import com.opensymphony.workflow.loader.ActionDescriptor
import com.opensymphony.workflow.loader.StepDescriptor

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("AP-1")
def workflowManager = ComponentAccessor.getWorkflowManager()
JiraWorkflow workflow = workflowManager.getWorkflow(issue);
def allactions = workflow.getAllActions()
log.error("All actions ID and names" + allactions.collect {it.name+ ' '+ it.id})

 In addition,I've verified Current User permission.

Is it okay to run the transition code in Script Console?

Mark Markov
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 9, 2018 edited

It's okay to run from Script Console. 
I check your code in my environment and it work perfectly.

Снимок экрана 2018-06-09 в 11.00.00.png

Check that transition 11 really exist from current issue status, if it exist try to execute it manually.

Also, issueService.validateTransition have method that allow you to bypass permissions, validators and conditions, you can try it.

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.workflow.TransitionOptions


TransitionOptions transitionOptions = new TransitionOptions.Builder().skipConditions().skipPermissions().skipValidators().build()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(user, issue.id, actionDescriptor.id , issueInputParameters, transitionOptions);

 

zaharovvv_suek_ru
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 9, 2018 edited

@Mark Markov Thank you very much! It was my mistake. I really confused 'transition id' and that transition was really not eligible from a previous transition. Sorry. Thank you very much!

zaharovvv_suek_ru
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 9, 2018

@Mark Markov Am I correctly understood that the above code of moving transitions should be put inside of post function of Workflow?

1 vote
Answer accepted
Alexey Matveev
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 8, 2018 edited

Hello,

Where do you call this script?

We had this problem in a post function. We used a different thread to move the issue to a different status.

zaharovvv_suek_ru
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 8, 2018 edited

@Alexey Matveev I run this script in the Script Console.

Am I correctly understood that the above code should be run in post function?

Alexey Matveev
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 9, 2018

I just asked, where you run the function. You run it from the Script Console and it is fine. It means you do not need a different thread. I think the problem is that transition 11 does not exist for the current status of your issue. 

zaharovvv_suek_ru
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 9, 2018

@Alexey Matveev Thank you very much! It was my mistake. I really confused 'transition id' and that transition was really not eligible from a previous transition. Sorry. Thank you very much!

zaharovvv_suek_ru
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 9, 2018

@Alexey Matveev  Am I correctly understood that the above code of moving transitions should be put inside of post function of Workflow?  

Alexey Matveev
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 9, 2018

It depends on your case. What do you want to do? What is your business requirement?

zaharovvv_suek_ru
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 9, 2018

@Alexey Matveev What I want to do is when an user moves an issue from a transition 'Open' to next transition 'In Progress', then other issues should be set to status 'Open'. So where should I put the code? 

Alexey Matveev
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 9, 2018

I see. Then you should paste the script either to a post function or to a listener. It depends on how many transitions must use the script. If it is a single transition, it is better to put it to a post function. If there are multiple transitions, then it is simpler to use a listener.

0 votes
Michael Kornatzki
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 27, 2021

Is it possible to change the status in the creation-transition as a postfunction?


For the "create issue"-transition i put a postfunction to change the status but i get the message  "You seem to have tried to execute a function in the workflow that is not valid for the current state of this operation."

I log the possible actions and the one i use is listed.

Then i change the script and use an issue which was created (and is also in the open-status).

If i then create a new issue the status of the hardcoded issue in the script is changed.

Michael Kornatzki
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 27, 2021
int ID_TRANSITION_ABSTIMMEN = 741

MutableIssue currentIssue
= ComponentAccessor.getIssueManager().getIssueObject(issue.getId())
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.setComment("performTransitionToAbstimmen")
IssueService.TransitionValidationResult validation = issueService.validateTransition(user, currentIssue.getId(), ID_TRANSITION_ABSTIMMEN, issueInputParameters)
if (validation.isValid()) {
IssueService.IssueResult result = issueService.transition(user, validation)
if (!result.isValid()) {
logger.error("${result.errorCollection}")
}
} else {
logger.error("not valid: ${validation.errorCollection}")
}
logger.debug("Vorgang (" + currentIssue.key + ") Statusübergang => abzustimmen.")

Will C
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.
May 10, 2022

@Michael Kornatzki Did you ever resolve this, I have the exact same problem now.

I have tried using Thread.start{} and putting the code inside a new thread but it fails on that too.

Any ideas?

Suggest an answer

Log in or Sign up to answer