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(); parameters.setRetainExistingValuesWhenParameterNotProvided(true); IssueService.TransitionValidationResult validationResult = issueService.validateTransition(assigneeUser, issue.getId(), clarificationDescriptor.getId(), parameters); if (validationResult.isValid()){ // Do Something } else{ System.out.println(validationResult.getErrorCollection().getErrorMessages()); }
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.
Where are you trying to run this code? Post function?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, it's an addon, that's something useful. But, for the third time, *where is it running*? Is it a post-function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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, issue.id, TRANSITION_ID, inputParams ) ErrorCollection col = transitionValidationResult.getErrorCollection() if(col.hasAnyErrors()){ //create events always come here with: "It seems that you have tried to perform..." getLog().error(col.getErrorMessages()); }else{ //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. Surely there's a way to make initial status programmatically conditional.
Thanks in advance for you help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not quite, I'm just trying to establish where the code is running, because you can only run code like this in certain places.
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.