Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

This document guides you on how to get more out of the Create issue post-function such as creating multiple issues one each based on the values of a multi-select field, linking newly created issues together, setting the field values of the newly created issue from the iterator and so on.

On this page:

Table of Contents
maxLevel3

Creating multiple issues

Using the "Multiple iterator" feature of the Create issue post-function, you can create multiple issues at once during the execution of this post-function,

...

 optionally linking them to the current issue. The iterator script is a Groovy expression that

...

must return an array or a collection of values.

...

 The post-function will iterate over this array or collection and create one new issue per value. The below sections explain some of the use cases.

Create one issue per value and set the field of the newly created issue

To create one issue each for the users jdoe,tblack and dcharlie and assign the newly created issues to the respective user

  1. In the Iterator section input

    Code Block
    languagejs
    ["jdoe","tblack","dcharlie"]
  2. Go to Set fields of new issue section

  3. Under Additional fields select "Assignee"

  4. Click on Add

  5. Select Set field value to Groovy expression option from the drop-down

  6. Input this script:

    Code Block
    languagejs
    it

To create one issue each for the users in a multi-user field

  1. In the Iterator section input

    Code Block
    languagejs
    issue.get("Multi-user picker field")
  2. To assign the newly created issues to the respective user:

  3. Go to Set fields of new issue section

  4. Under Additional fields select "Assignee"

  5. Click on Add

  6. Select Set field value to Groovy expression option from the drop-down

  7. Input this template:

    Code Block
    languagejs
    it

You can similarly create multiple issues for values in any multi-values field like Affects Version/s, Component/s, Multi-select field etc.

Build an iterator to create multiple issues and set fields of the newly created issues

Instead of being a simple string as in the example above, each value in the list can be an arbitrary Java object with multiple values and each object which will be available through the it variable. For example, each value can be a Groovy Map, allowing multiple values to be passed to each iteration of the post-function. If the iteration script returns:

Code Block
languagejs
[ 
  [assignee:"jdoe", summary:"Issue for John Doe"],

...

  [assignee:"tblack", summary:"Issue for Tim Black"]
]

then two new issues will be created. Under the "Set fields of new issue" you can set the Summary of the newly created issue to the result of this Groovy expression:

Code Block
languagejs
it.summary

and Assignee to the result of this Groovy expression:

Code Block
languagejs
it.assignee

Create issues from a combination of two custom fields

You can create multiple issues from a combination of two custom fields and set the respective fields of the newly created issue. For this, you'll need to generate an array of all possible combinations and provide it in the iterator. One issue will be created for each combination. Let's assume you have two Multi-select fields Resource and Environment, then your iterator logic will be something like:

Iterator logic

Code Block
issue.get("Resource").collectMany{resource -> issue.get("Environment").collect{[resource:resource.value,environment:it.value]}}

Setting fields

In the "Set fields of new issue" section, set the Resource field to the result of this Groovy expression:

Code Block
it.resource

and the Environment field to the result of this Groovy expression:

Code Block
it.environment

Cloning an issue and its linked issues

Using the Create issue post-function you can clone an issue and its linked issues too.

...

Let's assume on the trigger of the transition "Clone now" you want to clone a Story and issues linked to it through "is related to" link type to a different project.

Info

Clone Story: Add the Create issue post-function to the "Clone now" transition.

  1. Select the destination project from Project

  2. Select the Issue type as "Story"

  3. Select the link type as "is cloned by"

  4. Using the "Set fields of the new section" set the fields on the Story (copy or set with new values)

  5. Select the “Post-creation script” option and add this script:

    Code Block
    transientVars.mainIssueKey = newIssueKey
  6. Save the post-function.

Clone linked issues: Add another Create issue post-function to the "Clone now" transition below the above one:

  1. Select the destination project from Project

  2. Select the Issue Type as Calculated, with the Groovy expression:

    Code Block
    it.issuetype.name
  3. Input the Summary with Groovy expression:

    Code Block
    it.summary
  4. Select "Multiple issue creation" option

  5. In the iterator write the following script:

    Code Block
    issue.getLinkedIssues("is related to")
  6. Select the “Post-creation script” option and add this script:

    Code Block
    newIssue.linkIssue("relates to", transientVars.mainIssueKey)
  7. Save the post-function.

  8. Move it after the first post-function.

  9. Publish the workflow

Now when you trigger the transition "Clone now" the Story and its linked issues are cloned to the new project.

Cloning a Story and its subtasks

Info

Clone Story: Add the Create issue post-function to the "Clone now" transition.

  1. Select the destination project from Project

  2. Select the Issue type as "Story"

  3. Select the link type as "is cloned by"

  4. Using the "Set fields of the new section" set the fields on the Story (copy or set with new values)

  5. Select the “Post-creation script” option and add this script:

    Code Block
    transientVars.mainIssueKey = newIssueKey
  6. Save the post-function.

Clone Subtasks: Add another Create issue post-function to the "Clone subtasks" transition after the above one

  1. Select the destination project from Project

  2. Select the Issue Type as Calculated, with value

    Code Block
    it.issuetype.name
  3. Select the Parent issue as “Calculated” and input the following script

    Code Block
    transientVars.mainIssueKey
  4. Input the Summary as:

    Code Block
    it.summary
  5. Select "Multiple issue creation" option

  6. In the iterator write the following script:

    Code Block
    issue.subTaskObjects
  7. Save the post-function.

  8. Move it after the first post-function.

  9. Publish the workflow

Now when you trigger the transition "Clone now" the Story and its subtasks are cloned to the new project.

Link newly created issues

When using the "Multiple issue creation" feature of the Create Issue post-function, you can link the newly created issues together. There are two approaches to this as explained below. Consider you are creating 3 issues and this is your iterator script in the Multiple Issues Creation configuration:

Code Block
[
  [summary:"A first issue"],
  [summary:"A second issue"],
  [summary:"A third issue"]
]

The most straightforward way to create links between these new issues is to use this script in the Post-creation script configuration:

Code Block
transientVars.newIssues.findAll { it != newIssue }.each {
  it.linkIssue(10003L, "outward", newIssue)
}

Prevent issue creation when the transition is run the second time

When creating a single issue

If you are creating a single issue with the Create Issue(s) post-function, and that new issue is linked to the current issue, you can use the “conditional execution” section with a conditional execution script like:

Code Block
!issue.getLinkedIssues("link direction")

which will prevent the post-function from running if an issue is already linked to the current issue with the same link type direction (e.g. “blocks”).

When creating multiple issues

If you have configured a Create Issue(s) post-function to create multiple sub-tasks based on the selected values of a multi-select / checkboxes field, and you want to make sure that, if the transition is run again, only sub-tasks for values that were selected after the last transition execution are created, you cannot use conditional execution. Instead, you need to modify the Iterator script.

For example, if you iterator script is:

Code Block
issue.get("Checkboxes")

and you have added the “Checkboxes” field to the “Set fields of new issue” section and set it to:

Code Block
it.value

to create one new sub-task per selected value of the Checkboxes field, then you’ll need to update the iterator script to:

Code Block
issue.get("Checkboxes") - issue.subTaskObjects?.collectMany{it.get("Checkboxes")}

which will return the selected Checkboxes minus the Checkboxes values selected on sub-tasks.

The same approach applies if you are creating Stories inside Epics by replacing issue.subTaskObjects with issue.stories. It also works if you are creating issues linked to the current issues through a specific link type, by replacing issue.subTaskObjects with issue.getLinkedIssues(”link type name”).

Prevent loop on the Create transition

When creating a new issue during the creation of an issue, it leads to a recursive loop. For example:

  • If you are creating subtasks to a Task on the Create transition then the post-function will try to create sub-tasks to each newly created sub-task and you will see the error: "Cannot create a subtask to a subtask".

  • If you are creating tasks linked to the Story on the Create transition then the post-function creates linked tasks to each newly created task thereby creating a loop. JMWE identifies the loop and stops the issue creation with an error message: "Identified a loop. Execution Stopped."

To avoid this you can use the conditional execution section and break the loop. 

  1. In the first example, add a condition in the conditional execution template to check that the main issue (issue from which multiples issues are created) is not a subtask. 

    Code Block
    languagejs
    !issue.isSubTask()
  2. In the second example, identify the main issue by its issue type as follows. 

    Code Block
    languagejs
    issue.issuetype.name == "Story"
Info

You are viewing the documentation for Jira Data Center/Server.

On This Page

Table of Contents
minLevel1
maxLevel2
outlinefalse
typelist
printablefalse