How to auto-change issue status?

Hello,

I would like to implement post function script which run on Resolve Issue and Close Issue transitions and change issue status back to original if some conditions are fulfilled.

For example: post function script on "Resolve issue" transition step should change issue status to previous one if fix version does not equal some custom field version

Could you please advise how to make it if it's possible?

Thank you in advance.

Regards, Georgiy

2 answers

1 accepted

This widget could not be displayed.

> javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalStateException: You can not transition an issue with an invalid validation result.

It's telling you what is wrong... check the issue service javadocs, you need to look at the validation result (which has errors) before trying to do the transition.

Anyway, why don't you just use a validator to block the transition rather than confusing the user by having it transition to something unexpected?

If you really need to do this try using the fast track transition script with appropriate condition code. It's imperfect but it's likely to work better than if you write the same thing from scratch.

I don't use validator in this case because I was asked to make following functionality: user press Resolve button, and add some custom field values, then based on the input data the issue status should be changed to Resolved or remains in the current status, i.e. Open or Reopened. As far as I understood I have to make such functionality in post-function script. Do you think I am on the right way?

Could you please also tell where I can learn more about "fast track transition script "?

Thank you.

You can browse to the code from within the app - add the post-function, then click the view source link. https://studio.plugins.atlassian.com/wiki/display/GRV/Built-In+Scripts#Built-InScripts-Fasttracktransitionanissue

> Do you think I am on the right way?

Without having full access to the requirement hard to say, but to me it sounds like, if the user clicks Resolve, then they end up in Open or Reopened, that might lead to confusion.

Thank you Jamie for the link!

I tried simple condition (e.g. currentUser == issue.reporter, and others) and action as "Close Issue" just to test Fast track transition, but it does not work.

Might it be so that I missed something?

I use JIRA v5.0.6#733 and groovyrunner 2.0.6,

Just noticed that issue triggered to Closed status when I refreshed the view. Initially it showed Resolved status which should be be shown as the next status.

I managed to change issue status to Reopned and used condition in Fast-track built in script (called as the last post function) on Resolve Issue post function

issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("custom_field")) != issue.getFixVersions()

but the issue is shown as Resolved until the issue is refreshed.

Jamie, could you please advise to solve it? I think re-indexing might help but re-index issue is not available as the post function.


Yeah this is a known but that seems to affect more recent jira versions. The issue is reindexed, it's just that the page is rendered with a version of the issue object before the status change. It's in my backlog.

Jamie, thank you very much for information!

>The issue is reindexed, it's just that the page is rendered with a version of the issue object before the status change. It's in my backlog.

Did you mean that it will be fixed in upcoming Groovyrunner versions?

could you please give an example code how to set issue for example to "Open" status?

It would help me a lot.

Cheers, Georgiy

Hi Jobin,

I tried to implement it as the following

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.DefaultIssueService
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.bc.ServiceResultImpl
import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult
import com.atlassian.jira.issue.IssueInputParametersImpl

MutableIssue issue = issue
user = issue.getAssignee()

TransitionValidationResult validationResult = issueService.validateTransition(user, issue.getId(), 2, issueInputParameters) // 2 is the Close Issue transition ID
 
issueService.transition(user, validationResult)

but ened up with error as

2012-09-04 16:41:31,395 http-80-3 ERROR admin 1001x772x1 1i7xhfp 10.161.201.17 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issueService for class: Script35
2012-09-04 16:41:31,395 http-80-3 ERROR admin 1001x772x1 1i7xhfp 10.161.201.17 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: issueService for class: Script35
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)

which I think should be resolved by defining issueService.

and I could not find how to define issueInputParameters.

Could you please help with it?

Thank you.

Regards, Georgiy

Looks like you have a post function on the Close Issue Transition that is failing. A grrovy script?

Yes, it's groovy script and actually I try to call it on "Resolve Issue" transition step, i.e. I need to change status to Closed instead of Resolved for some conditions (conditions will be added later to the script).

Do you know whether it is even possible to do?

Where are you initializing the issueService variable? I am not a grrovy expert but you need something like this:

def issueService = ComponentManager.getInstance().getIssueService()

Thank you for your help. Yes, you are right. Initialization of issueService and issueInputParameters was missing. Now i added it as

def issueService = ComponentManager.getInstance().getIssueService()
issueInputParameters = issueService.newIssueInputParameters()

and have got following error

javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalStateException: You can not transition an issue with an invalid validation result.

Do you know what might be wrong here, please?

validationResult has some error. You will have to find the error and see what is going wrong.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

55 views 1 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you