Hello,
Is it possible to automate a cloning process (inc. all sub-tasks) when an issue is resolved?
Current Process:
On a daily basis my team work through an issue which has 14 sub-tasks associated to it. We currently have a template ticket which is cloned then the summary field is updated with todays date and work commences.
Desired outcome:
Once the existing issue is complete, a new clone is automatically generated with all sub-tasks ready to go.
So far, I have been able to clone a task when a custom field is equal to a particular value after a resolution event.
cfValues['cfExample']?.value == 'Example'
I have also added an additional issue action to update the summary on the newly cloned issue to todays date
def SummaryName = String.format('%tF', java.time.LocalDateTime.now())
issue.summary = SummaryName
The issue is that the above only clones the parent task and does not clone any of the sub-tasks. How would I go about cloning the sub-tasks over to the newly created issue?
Thank you.
Hi Paul,
How are you doing the cloning of tasks? Is it through listeners or through workflow post function?
You can use the below piece of code in cloning the sub-tasks.
def subtasks = issues.subTaskObjects
if (subtasks) {
subtasks.each { subtask ->
def subtasktoClone = issueFactory.cloneIssueWithAllFields(subtask)
def subtaskcloned = issueManager.createIssueObject(reporter, subtasktoClone)
subtaskManager.createSubTaskIssueLink(newissue, subtaskcloned, newissue.reporter)
}
}
Thanks,
Aditya
Many thanks for your response Aditya.
I'm looking to use listeners.
When I attempt to use the above it throws back some errors. You'll have to forgive me as I am new to Groovy script. I did try and resolve these by adding the below but it still throws back some errors due to undeclared variables.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.IssueManager
def issueFactory = ComponentAccessor.getIssueFactory()
def subtaskmanager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def subtasks = issue.subTaskObjects
if (subtasks) {
subtasks.each { subtask ->
def subtasktoClone = issueFactory.cloneIssueWithAllFields(subtask)
def subtaskcloned = issueManager.createIssueObject(reporter, subtasktoClone)
subtaskmanager.createSubTaskIssueLink(newissue, subtaskcloned, newissue.reporter)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paul,
I've just shared a piece of code. Can you share your complete code and the error to look at it?
Thanks,
Aditya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I'm using the following script and it executes successfully without an error however the sub-tasks are not being cloned.
The cloning of sub-tasks should be based on the original parent ticket which was moved to complete. Is this code doing that, or is it based on the new cloned ticket which doesn't have any sub-tasks?
import java.time.LocalDate
import com.atlassian.jira.component.ComponentAccessor
def SummaryName = LocalDate.now().plusDays(1).toString()
def subtaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subtasks = issue.getSubTaskObjects()
if (subtasks)
{
subtasks.each {subtask ->
def toclone = issueFactory.cloneIssueWithAllFields(subtask)
def cloned = issueManager.createIssueObject(issue.reporter, toclone)
subtaskManager.createSubTaskIssueLink(issue, cloned, issue.reporter)
log.error("CLONED ISSUE KEY: ${cloned.getKey()}")
}
}
issue.summary = SummaryName
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.