It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to change the state of an issue in jira?

I want to change the state of an issue as soon as it is created (based on a certain condition). I have used the following code to change the state of the issue:


JiraWorkflow workflow = ComponentAccessor.getWorkflowManager().getWorkflow(issue);
StepDescriptor stepDescriptor = workflow.getLinkedStep(issue.getStatusObject());
ActionDescriptor clarificationDescriptor=null;
for(int i=0;i<stepDescriptor.getActions().size();i++){
ActionDescriptor actionDescriptor = (ActionDescriptor) stepDescriptor.getActions().get(i);
String actionName = actionDescriptor.getName();
if(actionName.equalsIgnoreCase("Request Clarification")){
clarificationDescriptor = actionDescriptor;
if(clarificationDescriptor !=null){
User assigneeUser = issue.getAssigneeUser();
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters parameters = issueService.newIssueInputParameters();
IssueService.TransitionValidationResult validationResult = issueService.validateTransition(assigneeUser, issue.getId(), clarificationDescriptor.getId(), parameters);
 if (validationResult.isValid()){
// Do Something

But this gives me the following error: 

It seems that you have tried to perform a workflow operation (Received Clarification) that is not valid for the current state of this issue (INBOX-50). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.


I have cross verified that my workflow is correct. Also when I am trying to change the state through curl, I am able to do it. So what is the problem with the above code.


3 answers

1 vote

Where are you trying to run this code?  Post function?

I just posted the code above which I am trying to run as soon as the issue is created.

You've missed the point of the question. "as soon as the issue is created" tells me nothing about where you're running it. Is it in a post function? If not, then WHERE is it run?

I am creating the issue manually in jira. I have a plugin which I have uploaded in jira. There as soon as the event is created, I run the above code.

Ok, it's an addon, that's something useful. But, for the third time, *where is it running*? Is it a post-function?

0 votes

Hello there,


I believe what Nic is saying is that it'd be easier to use a plugin of some sort in order to do it directly in your workflow. I'm pretty sure that you can use Script runner, for example, to automatically check for the ticket status/fields and decide to where it should go.

Have you attempted something like that before?


Not quite, I'm just trying to establish where the code is running, because you can only run code like this in certain places.

Hi @Nic Brough [Adaptavist] - we've been going round/round with this.  We're using script-runner event listener (not post-function) and we think this is a race condition.  We see this other occasions but every time on create events.

//this debug always returns the correct initial status and expected transition id
logger.debug("Issue Status is " + issue.getStatusObject().name + " Transition ID is " + TRANSITION_ID)

IssueService issueService = ComponentAccessor.getIssueService()
IssueInputParameters inputParams = issueService.newIssueInputParameters()
inputParams.setComment("Some Comment")

IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(currentUser,, TRANSITION_ID, inputParams )

ErrorCollection col = transitionValidationResult.getErrorCollection()
	//create events always come here with: "It seems that you have tried to perform..."
	//create events never reach here
    IssueService.IssueResult issueResult = issueService.transition(currentUser, transitionValidationResult)

When we debug, it reports the newly-created issue's initial status correctly so it seems logical that the original transaction still has a lock on the object and the returned error about "a workflow operation (X) that is not valid. The likely cause is that somebody has changed the issue recently..." is, of course, incorrect. The "somebody" is the creator of the issue.

Is there a way to have it simply wait until other transactions are complete?

Fast-Track Postfunctions simply do not work on create-events so event listeners seem to be the only way only we can't get them to work either. :sad:  Surely there's a way to make initial status programmatically conditional.

Thanks in advance for you help.

Suggest an answer

Log in or Sign up to answer

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