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. |
...
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.
...
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
Code Block language js ["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:
Code Block language js it
To create one issue each for the users in a multi-user field
In the Iterator section input
Code Block language js 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:
Code Block language js it
...
Code Block | ||
---|---|---|
| ||
[ [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 | ||
---|---|---|
| ||
it.summary |
and Assignee to the result of this Groovy expression:
Code Block | ||
---|---|---|
| ||
it.assignee |
...
Info | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Clone Story: Add the Create issue post-function to the "Clone now" transition.
Clone Subtasks: Add another Create issue post-function to the "Clone subtasks" transition after the above one
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:
Code Block | ||
---|---|---|
| ||
[
{
"summary":"A first issue"
},
{
"summary":"A second issue"
},
{
"summary":"A third issue"
}
] |
Using newIssueKeys
variable
This is a very generic approach in which you can use the newIssueKeys
global variable that exposes the array of the issue keys of the issues already created by the post-function during previous iterations. For example, if your iterator value is an array of three values (three issues will be created), during the creation of the third issue, newIssueKeys
global variable array holds the first two issue keys. This way, you can add in your Iterator objects information about the links to create between issues.
For example
Add linking information to the above array as shown below, where
...
linkTo: represents an index pointing to the issue to be linked to. 0
for the first issue, 1
for the second issue and so on.
...
linkTypeName: represents the name of the link type to be created, like, Blocks
direction: represents the direction to be linked to, like, outward
Code Block |
---|
[
{
"summary":"A first issue",
},
{
"summary":"A second issue",
"linkTo": 0,
"linkTypeName": "Blocks",
"direction": "inward"
},
{
"summary":"A third issue",
"linkTo": 1,
"linkTypeName": "Blocks",
"direction": "outward"
}
] |
...
Under the "Set fields of new issue" select Linked Issues
field
Select "Set field value to" in the drop-down and input the following template:
Code Block | ||
---|---|---|
| ||
[
{% if it.linkTo != null %}
{
"type": {"name":"{{it.linkTypeName}}"},
"{{it.direction}}Issue": {"key":"{{newIssueKeys[it.linkTo]}}"}
}
{% endif %}
] |
Now when the transition is triggered
3 issues are created,
the second issue is linked to the first one through "is blocked by" link and
the third issue is linked to the second by the "blocks" link.
Using the iterator
This is an easier approach in which you can specify the issue links to create in the iterator section., using the following syntax:
...
Add the "Create issue" post-function
...
Select "Multiple issue creation"
Add the following information under the "Iterator"
Code Block |
---|
[
{
"summary":"A first issue"
},
{
"summary":"A second issue",
"issueLinks": [
{"linkName":"blocks","toIssue":1}
]
},
{
"summary":"A third issue",
"issueLinks": [
{"linkName":"relates to","toIssue":2}
]
}
] |
For each value, an issueLinks
property can be specified, which contains an array of links to create. Each link is specified by:
linkName: Indicates the link direction name as it appears on the issue (e.g. "blocks" or "is blocked by")
toIssue: Indicates the issue link to. It contains the 1-based index of the issue to link to;
1
being the first issue created by the iterator,2
the second, etc.. If0
is specified, then the new issue is linked to the issue being transitioned.
Prevent issue creation when the transition is run the second time
To avoid creating a second issue when the transition is run a second time you can use the jmwe.last.issue.created
(see here for more information) property to check that there is no issue created already by the post-function. In the conditional execution section, input the template:
Code Block |
---|
{{ issue | issueProperty("jmwe.last.issue.created") == null }} |
This will avoid the creation of an issue by the post-function, the second time the transition is triggered.
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
...
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 language js !issue.isSubTask()
In the second example, identify the main issue by its issue type as follows.
Code Block language js issue.issuetype.name == "Story"
The best is to use the
jmwe-created-from
property of the issue; Using this approach check that the issue is not created from another issue.Code Block language js {{ issue | issueProperty("jmwe-created-from") == null }}
Workaround to move an issue and its linked issues
Moving issues to a new project is not supported by the Jira Cloud APIs, so it cannot be implemented by JMWE or any other app. A workaround is to re-create the task and its linked issues in the destination project and delete the main issue and its linked issues. See here how to clone a task and its linked issues.
...