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

Custom script listener to transition issues in a sprint

Stuti Golwala Apr 03, 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

0 votes
Answer accepted
Stuti Golwala Apr 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

0 votes
Antoine Berry Apr 04, 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 Apr 04, 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 Apr 05, 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 Stuti Golwala likes this
Stuti Golwala Apr 05, 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 Apr 05, 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 Apr 08, 2019

You are missing the class, use this import

import com.atlassian.jira.issue.IssueInputParametersImpl
Like Stuti Golwala likes this
Stuti Golwala Apr 08, 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 Apr 09, 2019 • edited

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 Apr 09, 2019

Makes sense to me.

I will try it out.

Thanks!

Stuti Golwala Apr 11, 2019

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

1,456 views 3 14
Read article

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