How to auto-change issue status?

Georgiy Senenkov September 2, 2012

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

0 votes
Answer accepted
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2012

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

Georgiy Senenkov September 3, 2012

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.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2012

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.

Georgiy Senenkov September 4, 2012

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,

Georgiy Senenkov September 4, 2012

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.

Georgiy Senenkov September 4, 2012

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.


JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 5, 2012

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.

Georgiy Senenkov September 5, 2012

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?

Georgiy Senenkov September 3, 2012

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

It would help me a lot.

Cheers, Georgiy

Georgiy Senenkov September 3, 2012

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

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2012

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

Georgiy Senenkov September 3, 2012

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?

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2012

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

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

Georgiy Senenkov September 3, 2012

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?

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2012

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