Advanced configuration and usage of the Create issue post-function
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.
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
In the Iterator section input
["jdoe","tblack","dcharlie"]
Go to
Set fields of new issue
sectionUnder
Additional fields
select "Assignee"Click on
Add
Select
Set field value to Groovy expression
option from the drop-downInput this script:
it
To create one issue each for the users in a multi-user field
In the Iterator section input
issue.get("Multi-user picker field")
To assign the newly created issues to the respective user:
Go to
Set fields of new issue
sectionUnder
Additional fields
select "Assignee"Click on
Add
Select
Set field value to Groovy expression
option from the drop-downInput this template:
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:
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:
and Assignee to the result of this Groovy expression:
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
Setting fields
In the "Set fields of new issue" section, set the Resource field to the result of this Groovy expression:
and the Environment field to the result of this Groovy expression:
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.
Clone Story: Add the Create issue post-function to the "Clone now" transition.
Select the destination project from
Project
Select the Issue type as "Story"
Select the link type as "is cloned by"
Using the "Set fields of the new section" set the fields on the Story (copy or set with new values)
Select the “Post-creation script” option and add this script:
Save the post-function.
Clone linked issues: Add another Create issue post-function to the "Clone now" transition below the above one:
Select the destination project from
Project
Select the Issue Type as Calculated, with the Groovy expression:
Input the Summary with Groovy expression:
Select "Multiple issue creation" option
In the iterator write the following script:
Select the “Post-creation script” option and add this script:
Save the post-function.
Move it after the first post-function.
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
Clone Story: Add the Create issue post-function to the "Clone now" transition.
Select the destination project from
Project
Select the Issue type as "Story"
Select the link type as "is cloned by"
Using the "Set fields of the new section" set the fields on the Story (copy or set with new values)
Select the “Post-creation script” option and add this script:
Save the post-function.
Clone Subtasks: Add another Create issue post-function to the "Clone subtasks" transition after the above one
Select the destination project from
Project
Select the Issue Type as Calculated, with value
Select the Parent issue as “Calculated” and input the following script
Input the Summary as:
Select "Multiple issue creation" option
In the iterator write the following script:
Save the post-function.
Move it after the first post-function.
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:
The most straightforward way to create links between these new issues is to use this script in the Post-creation script configuration:
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:
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:
and you have added the “Checkboxes” field to the “Set fields of new issue” section and set it to:
to create one new sub-task per selected value of the Checkboxes field, then you’ll need to update the iterator script to:
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.
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.
In the second example, identify the main issue by its issue type as follows.
You are viewing the documentation for Jira Data Center/Server.
On This Page
- 1 Creating multiple issues
- 1.1 Create one issue per value and set the field of the newly created issue
- 1.2 Build an iterator to create multiple issues and set fields of the newly created issues
- 1.3 Create issues from a combination of two custom fields
- 1.4 Cloning an issue and its linked issues
- 1.5 Cloning a Story and its subtasks
- 2 Link newly created issues
- 3 Prevent issue creation when the transition is run the second time
- 4 Prevent loop on the Create transition