Is there a way to use postfunctions to clone a subtask when a subtask transitions to a certain status.
For some reason scriptrunner doesn't allow for the selection of subtasks when using the clone postfunction.
Use Case:
When a subtask enters a failed status, we want a bug subtask created under the same parent.
Hi, @Duane Cronkite
Maybe Jira Automation? :)
Ok, ok, just joking, I remember, you use server )
As for your answer, it's not a simple task, because script needs to know, what fields must be set. Simple version can create basic sub-task with needed issue-type, summary, description and assignee, but copying other custom fields is very tricky case.
lol!
would it be easy if we only copied over:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, I think, it will help
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
IssueManager issueManager = ComponentAccessor.getIssueManager()
ConstantsManager constantsManager = ComponentAccessor.getConstantsManager()
MutableIssue issue = issue as MutableIssue
MutableIssue parentIssue = issueManager.getIssueObject(issue.key)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Set exact name of sub task you're trying to create
String issueType = "Sub-Bug"
MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()
newIssue.setProjectObject(issue.getProjectObject())
newIssue.setIssueType(constantsManager.allIssueTypeObjects.findByName(issueType))
newIssue.setSummary("BUG: preface")
newIssue.setDescription(issue.description)
newIssue.setAssignee(issue.assignee)
newIssue.setReporter(user)
newIssue.setLabels(null)
newIssue.setComponent(null)
newIssue.setPriorityId('3')
newIssue.setDueDate(null)
ComponentAccessor.issueManager.createIssueObject(user, newIssue)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
okay it looked like it successfully created a bug but the bug is somehow being listed as a subtask of a subtask. It is not appearing as a subtask on the parent.
TP-168 test 2 is a subtask which is strange that its appearing like its the bug subtask parent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's crazy. I'll check it. In script it must have been linked to parent.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
and for the summary what I meant was Bug: (clone summary of the source ticket).
So Bug: is the preface before the source summary if that makes sense.
I didn't check if description copied over yet.
and I appreciate all the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found problem.
This is working (at least on my instance):
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
package Examples.Postfunctions
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
IssueManager issueManager = ComponentAccessor.getIssueManager()
ConstantsManager constantsManager = ComponentAccessor.getConstantsManager()
MutableIssue issue = issue as MutableIssue
MutableIssue parentIssue = issueManager.getIssueObject(issue.parentObject.key)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Set exact name of sub task you're trying to create
String issueType = "Sub-Bug"
MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()
newIssue.setProjectObject(issue.getProjectObject())
newIssue.setIssueType(constantsManager.allIssueTypeObjects.findByName(issueType))
newIssue.setSummary("BUG: ${issue.summary}")
newIssue.setDescription(issue.description)
newIssue.setAssignee(issue.assignee)
newIssue.setReporter(user)
newIssue.setLabels(null)
newIssue.setComponent(null)
newIssue.setPriorityId('3')
newIssue.setDueDate(null)
ComponentAccessor.issueManager.createIssueObject(user, newIssue)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
once again you made my day! I'll send you a connect on Linkedin! A++++
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Evgenii : Is there a way to add a "link" between the source and created subtask to the code.
"Relates to" link will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Duane Cronkite
It depends from your environment, IDs of link types can differ from mine.
You can use such code (adopted to your environment, of course):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
// Set user, that will link issues
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Set inward or outward link
Long sequence = 1L
// Set link type ID
Long issueLinkTypeId = 10000L
ComponentAccessor.issueLinkManager.createIssueLink(fromIssue.id, toIssue.id, issueLinkTypeId, sequence, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
received this error:
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script668.groovy: 45: The current scope already contains a variable of the name user @ line 45, column 17. ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() ^
I added this link code directly to the bottom of the other code above. I tried removing the user piece etc but couldn't figure out how to get it to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, @Duane Cronkite
What's the sense in it? This are 2 subtasks for one issue.
Anyway, it can be made with something like this:
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.ConstantsManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
IssueManager issueManager = ComponentAccessor.getIssueManager()
ConstantsManager constantsManager = ComponentAccessor.getConstantsManager()
MutableIssue issue = issue as MutableIssue
MutableIssue parentIssue = issueManager.getIssueObject(issue.parentObject.key)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Set exact name of sub task you're trying to create
String issueType = "Sub-Bug"
// Set inward or outward link
Long sequence = 1L
// Set link type ID
Long issueLinkTypeId = 10000L
MutableIssue newIssue = ComponentAccessor.getIssueFactory().getIssue()
newIssue.setProjectObject(issue.getProjectObject())
newIssue.setIssueType(constantsManager.allIssueTypeObjects.findByName(issueType))
newIssue.setSummary("BUG: ${issue.summary}")
newIssue.setDescription(issue.description)
newIssue.setAssignee(issue.assignee)
newIssue.setReporter(user)
newIssue.setLabels(null)
newIssue.setComponent(null)
newIssue.setPriorityId('3')
newIssue.setDueDate(null)
ComponentAccessor.issueManager.createIssueObject(user, newIssue)
ComponentAccessor.subTaskManager.createSubTaskIssueLink(parentIssue, newIssue, user)
ComponentAccessor.issueLinkManager.createIssueLink(issue.id, newIssue.id, issueLinkTypeId, sequence, user)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.