Custom script listener to transition issues in a sprint

Stuti Golwala April 3, 2019

I am trying to move all the issues with Done status to Close status when a sprint is closed.

I have custom listener to perform the operation but the script didn't work.

custom_script_groovy.JPG

I am not sure what's wrong with the script.

Any help on this would be greatly appreciated.

Thanks!

2 answers

1 accepted

1 vote
Answer accepted
Stuti Golwala April 11, 2019

For those who are looking to perform the same using Script Runner, here is the code that worked for me:

custom_script_groovy.JPG

Fabio Manzoni February 3, 2020

Hi @Stuti Golwala can you help please?

I changed your code a little bit to transition an issue when the sprint its started.

The logs shows this error.

 

error log.pngAnd this is my code.

my code.png

Thank you, 

Fabio

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 4, 2020

Hi @Fabio Manzoni ,

line 27 replace

"issueID ->"

with

"issueId ->"
Fabio Manzoni February 5, 2020

Hi @Antoine Berry

The error it's the same.

 

2020-02-05 11:24:05,918 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2020-02-05 11:24:05,918 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintStartedEvent, file: null
groovy.lang.MissingPropertyException: No such property: actionId for class: Script1419
 at Script1419$_run_closure1.doCall(Script1419.groovy:30)
 at Script1419.run(Script1419.groovy:27)
Fabio Manzoni February 5, 2020

@Antoine Berry 

Worked!!!

I changed the  actionID to actionId and not the issueId.

Thank you for your help

Fabio

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 4, 2019

Hi,

Providing the logs would help debugging. Anyway I use a different approach that has been working fine, which would be (using your parameters) : 

import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils

WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class );
workflowTransitionUtil.setIssue(issue);
workflowTransitionUtil.setUserkey(currentUser.getKey())
workflowTransitionUtil.setAction(actionId);
workflowTransitionUtil.progress();

Antoine

Stuti Golwala April 4, 2019

Hi Antoine,

Thank you for your reply.

From your code, will it move all issues or a particular issue to close status? Also, do I have to mention the issue id in the code? If yes, then I am afraid to use it as I don't want the issue to be static. 

I am sorry if I have not understood your code. This is my first groovy script.

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2019

Hi,

You are welcome to ask any question !

If you are using a Script Listener, the script is triggering on the event(s) you are mapping to it.

Events are triggered in workflow (Issue created/Issue closed...) transitions. You can change which event is triggered in a transition, and you can create custom events.

There are also system events (Issue Assigned/Issue updated/Issue commented...). In previous cases you can use "issue" as your object, i.e. the issue on which the event is triggered - Sorry if you knew all this already.

So in your case I guess you are using the SprintClosedEvent event. I have never used it, but you can find an exemple here : https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_jira_software_events

In this case your are gonna need to use the "event" object, to retrieve the sprint which has been closed. Once you have retrieved the issues that you want to update, you can use my script for each of them.

As this not very well documented, I would advise to use logs a lot to check objects values and their class (using .getClass()) to check the documentation, such as the sprint.

Good luck, very interested in the outcome. :)

Like # people like this
Stuti Golwala April 5, 2019

Hi Antoine,

Thank you for the detailed explanation. I will try to script and see what is comes out to.

I will surely post the solution here whenever I have it.

Thanks again!

Stuti Golwala April 5, 2019

Hey Antoine,

Forgot to attach the logs of my code that I have attached in my first post.

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-04-05 19:04:31,708 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-04-05 19:04:31,710 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintClosedEvent, file: <inline script>
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script89.groovy: 29: unable to resolve class IssueInputParametersImpl 
 @ line 29, column 95.
   rrentUser, issue.id, actionId,new IssueI
                                 ^
1 error
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2019

You are missing the class, use this import

import com.atlassian.jira.issue.IssueInputParametersImpl
Like Stuti Golwala likes this
Stuti Golwala April 8, 2019

Thank you Antoine for the catch.

I have added it but still getting an error.

Code:

custom_script_groovy.JPG

Error:

Time (on server): Mon Apr 08 2019 09:19:07 GMT-0700 (Pacific Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2019-04-08 16:19:07,924 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-04-08 16:19:07,924 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintClosedEvent, file: <inline script>
groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.greenhopper.api.events.sprint.SprintClosedEvent
 at Script117.run(Script117.groovy:21)

I have added the library "com.atlassian.greenhopper.api.events.sprint.SprintClosedEvent" but still failing the execution.

Not sure what to add/remove.

Thanks!

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 9, 2019

The problem seems to be that your "issue" object is null. I would advise to log the objects you are creating so you can see what is working and what is not. Example after line 15 : 

log.error("issue : " + issue)

In this particular case since you are triggering a Sprint Closed event, the listener is bound to the Sprint object and not the issue, that is why your issue is null (That is what I would assume since I have not tried using this particular event).

i.e.

event.issue

returns null. That is my guess. You need to retrieve the issues from the sprint object (event.sprint) as in the example provided by scriptrunner.

Antoine

Stuti Golwala April 9, 2019

Makes sense to me.

I will try it out.

Thanks!

Stuti Golwala April 11, 2019

I have found a solution to it. Posting the code soon.

Germán Rojas Tapia July 3, 2019

Hi, Dear Stuti, do you have found a solution?

Suggest an answer

Log in or Sign up to answer