Im using scriptrunner to create a linked case on a transition, but i want to use the "additional issue actions" option more.
The show a popup messages works fine, i also want to add a comment onto the current issue.
Thanks
Two objects in that box. issue is the new clone, also inside doAfterCreate, the docs are explicit about that. The original is sourceIssue, the same object the "Set custom field from parent/source issue" snippet in your picker uses, even though the docs page doesn't name it.
No groovy needed for the comment though. Add a second post-function on the same transition, the built-in "Adds a comment to this issue" from scriptrunner. Its issue is the transitioning one. The comment field takes templating, e.g. ${issue.getCustomFieldValue('TextField')}, and the arrows on the right move it after the clone step if it needs to sit there.
Does the comment need the new issue's key in it, or is a plain "linked case created" enough?
Hi, Thanks for your reply.
The comment needs to go on the current issue not the linked issue that was created. Ive tried to add a post function on the create transition of the "ABD" issue type (linked issue), but it does not work.
Hi Rob,
Adding to Mihai's answer - you don't need anything on the ABD workflow for this. It can go in the same Additional issue actions box: put the comment inside doAfterCreate and add it to sourceIssue, which is the issue you are transitioning.
doAfterCreate
sourceIssue
I checked this on my own instance before answering (Jira DC 9.6, a test project, "Clones an Issue and Links" on a Start Progress transition, link type "relates to"). After the transition the current issue had the comment with the new key in it, the new issue had no comments, and the link was there.
import com.atlassian.jira.component.ComponentAccessor doAfterCreate = { def commentManager = ComponentAccessor.commentManager def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser commentManager.create(sourceIssue, user, "Linked case " + issue.key + " was created from this issue.", true) }
Inside doAfterCreate, issue is the new issue and it already exists, so issue.key gives you the real key. Outside that block it's not created yet and issue.key fails. The last argument (true) dispatches the Issue Commented event, so notifications go out like for a normal comment. The comment was also searchable right away on my side (comment ~ "Linked case").
issue
issue.key
true
comment ~ "Linked case"
About the create transition you tried on ABD: a post function there runs for the new issue, since that's the issue being created. So "this issue" in that place is the linked case, not the one you started from. Mihai's option with the built-in "Add a Comment to this Issue" comments on the issue being transitioned, so it has to sit on the same transition as the clone, not on ABD. That's fine for a fixed text, but if you want the new key in the comment, doAfterCreate is simpler because issue.key is right there.
One small thing: if your popup code is already inside a doAfterCreate block, put the comment lines in that same block. A second doAfterCreate = { } replaces the first one, and the popup would stop showing. Also, in my test the clone post function was right after "Re-index an issue" in the list, which is where the ScriptRunner docs say it should go.
doAfterCreate = { }
Hope that helps.
It looks like you're new here. Sign in or register to get started.