Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

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.

On this page:

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

    ["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:

    it

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

  1. In the Iterator section input

    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:

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.

  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:

  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:

  3. Input the Summary with Groovy expression:

  4. Select "Multiple issue creation" option

  5. In the iterator write the following script:

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

  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

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:

  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

  3. Select the Parent issue as “Calculated” and input the following script

  4. Input the Summary as:

  5. Select "Multiple issue creation" option

  6. In the iterator write the following script:

  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.

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. 

  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. 

  2. In the second example, identify the main issue by its issue type as follows.