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:
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's okay to run from Script Console.
I check your code in my environment and it work perfectly.
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Mark Markov Am I correctly understood that the above code of moving transitions should be put inside of post function of Workflow?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev I run this script in the Script Console.
Am I correctly understood that the above code should be run in post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev Am I correctly understood that the above code of moving transitions should be put inside of post function of Workflow?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It depends on your case. What do you want to do? What is your business requirement?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.