Snippets

Adaptavist Auto creating tasks and sub-tasks for an Epic

Created by Bobby Bailey
/*
 * All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner
 * license shall be granted a  non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed
 * or amended and must be included in any circumstances where the code snippet is shared by You or a third party."
*/

def curIssue = event.issue

def issueType = curIssue.issueType.id

if(issueType == '10000'){
    def issueEpicName = curIssue.epicName
    
    //if creating Susbtasks: 
    // We can use the HAPI createSubTask function to create sub-tasks for the originally created issue
    // NOTE : ${} allows us to call a variable and put it in a string, so we can dynamically get
    // the name of the epic and use it in the creation of issues
    
    curIssue.createSubTask('Sub-task') {
        setSummary("${issueEpicName} - A")
    }

    curIssue.createSubTask('Sub-task') {
        setSummary("${issueEpicName} - B")
    }

    curIssue.createSubTask('Sub-task') {
        setSummary("${issueEpicName} - C")
    }

    curIssue.createSubTask('Sub-task') {
        setSummary("${issueEpicName} - D")
    }
    

    // If creating normal tasks:
    // We use HAPI's Issue functionality to create the new Task, and then link
    // to the original created Epic using relates to (choose own link type)
    // NOTE : ${} allows us to call a variable and put it in a string, so we can dynamically get
    // the name of the epic and use it in the creation of issues

    def issueTaskA = Issues.create('WEB', 'Task') {
        setSummary("${issueEpicName} - A")
    }
    issueTaskA.link('relates to', curIssue)

    def issueTaskB = Issues.create('WEB', 'Task') {
        setSummary("${issueEpicName} - B")
    }
    issueTaskB.link('relates to', curIssue)

    def issueTaskC = Issues.create('WEB', 'Task') {
        setSummary("${issueEpicName} - C")
    }
    issueTaskC.link('relates to', curIssue)

    def issueTaskD = Issues.create('WEB', 'Task') {
        setSummary("${issueEpicName} - D")
    }
    issueTaskD.link('relates to', curIssue)
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.