Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic creation of field-dependent number of subtask

Rafał Falisz February 1, 2023

It's my start in programming journey, hope you can help me with that (explanation would be a massive help) 

def Publication = issue.fields.customfield_15190?.value
def Structure =  issue.fields.customfield_15189?.value
def Iteration = issue.fields.customfield_14254?.value
def key = issue.key
def summary = issue.fields.summary
def priority = issue.fields.priority

List fieldsMaps = []


if (Publication.contains("CB"))
{
    logger.info("creating CB")
    fieldsMaps.add(["project":["key": "TPP"], "issuetype":["id": "11757"]]) //Core - 11757
}  
if (Publication.contains("Fs"))
{
    logger.info("creating Fs")
    fieldsMaps.add(["project":["key": "TPP"], "issuetype":["id": "11758"]]) //Focus - 11758
}  
if (Publication.contains("NOF"))
{
    logger.info("creating NOF")
    fieldsMaps.add(["project":["key": "TPP"], "issuetype":["id": "11759"]]) //NOF - 11759
}  
if (Publication.contains("Others"))
{
    logger.info("creating ")
    fieldsMaps.add(["project":["key": "TPP"], "issuetype":["id": "11760"]]) //Other - 11760
}  


def createdBacklogItems = []

//build a list of alrady linked implementation tasks
def implementationKeys = [:]
def linkedIssues = issue.fields.issuelinks
logger.info("${linkedIssues}")
for (linkedIssue in linkedIssues) {
    def implementationKey = (linkedIssue.inwardIssue?: linkedIssue.outwardIssue).key
    if (linkedIssue.type.name == "Issue split") {
            implementationKeys[implementationKey.split("-")[0]] = implementationKey
    }
}
logger.info("${implementationKeys}")

for(backlogItem in fieldsMaps)
    {
    backlogItem["summary"] = summary
    logger.info(backlogItem.toString()
    )
        //creation
        def createdIssue = post("/rest/api/3/issue")
            .header("Content-Type", "application/json")
            .body([
                fields: backlogItem
                ])
                .asObject(Map)
                .body
               
        logger.info("${createdIssue}")
        createdIssueKey = createdIssue.key
        if (!createdIssueKey){
            throw new Exception("Creation has not succeeded")
        }
        }
        //create link
        def resultLink = post("/rest/api/3/issueLink")
            .header("Content-Type", "application/json")
            .body([outwardIssue: [
                            key: issue.key
                        ],
                        inwardIssue: [
                            key: createdIssueKey
                        ],
                        type: [
                            name: "Issue split"
                            ]
                   
                ]).asString()
        logger.info("${resultLink}")

 The process should look like this:

1. Each time ticket reaches a certain status (workflow post-function), a certain number of cases of a certain type should be automatically created

Publication - is a field that allows you to choose what type of case you want to create

Iteration - determines the number of created cases

Structure - also determines the number of created cases (this field has 2 options:

  • Option A - there should be  no change fot the number defined in the Iteration field
  • Option B - the number defined in the iteration field should be divided in half

2. Second step is to link newly created issues only with their parent

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 6, 2023

Hi @Rafał Falisz

Were you able to find a solution for this?

Thank you and Kind regards,
Ram

Suggest an answer

Log in or Sign up to answer