Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,294,625
Community Members
 
Community Events
165
Community Groups

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

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

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

@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?

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);

 

@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!

@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

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.

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

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

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. 

@Alexey Matveev _Appfire_ 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!

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

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

@Alexey Matveev _Appfire_ 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? 

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.

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.

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.")

@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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you