Versions Compared

Key

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

...

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 option from the drop-down

  6. Input this template:

    Code Block
    languagejs
    {{it}}

...

  1. In the Iterator section input

    Code Block
    languagejs
    {{ issue.fields["Multi user picker"] | join(",","accountId") }}
  2. To assign the newly created issues to the respective user:

    1. Go to Set fields of new issue section

    2. Under Additional fields select "Assignee"

    3. Click on Add

    4. Select Set field value to option from the drop-down

    5. Input this template:

      Code Block
      languagejs
      {{it}}

...

Instead of a list of values or an array of values as in the examples above, each value in the list can be an arbitrary JavaScript object with multiple values and each object will be available through the it variable in the rest of the post-function configuration. For example, if the iterator returns the following:

...

Using the Sequence of post-function 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 an Epic and its Stories to a different project.

Panel
titleClone an Epic and its Stories
Info

Create a sequence

  1. Add the "Sequence of post-functions" post-function to the "Clone now" transition.

  2. Click on "Add post function" 

  3. Clone Epic: Add the Create issue

  4. In the sequence add the "Create issue" post-function.

Panel
titleClone an Epic and its Stories

Create a sequence

  1. Add the Sequence of post-functions post-function to the "Clone now" transition.

  2. Click on "Add post function" 

  3. Clone Parent: Add the Create issue post-function.

    1. Select the destination project from Project

    2. Select the Issue type as "Calculated"

    3. Input the template {{ issue.fields.issuetype.name }}

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

    5. Save the post-function.

  4. Clone Subtasks: Add a "Transition Linked Issues" post-function configured as

    1. Input the transition name as "Clone Subtasks" (will be created later)

    2. Select the Link type as "is cloned by"

    3. Save the post-function.

  5. Click on "Add"

  6. Publish the workflow

Create "Clone Subtasks" transition

  1. On the parent workflow of the destination project (on the same workflow if both parent and subtask share the same workflow), create a transition named "Clone Subtasks" on the Create transition to the same initial status.

  2. Hide that transition from users by adding a "Hide From User Condition"

Clone Subtasks: Add the Create issue post-function to the "Clone Subtasks" transition

  1. Select the Project as "Same as current issue"

  2. Select the "Issue Type" as "Sub-task"

  3. Select the “Parent issue” as “Current issue”

  4. Input the Summary as:

    Code Block
    {{it.fields.summary}}
  5. Select "Create Multiple Issues" checkbox under "Multiple issue creation"

  6. In the iterator write the following script:

    Code Block
    {% set from = issue | issueProperty("jmwe-created-from") | field("key") %}
    {{issue | linkedIssues( "clones" ) | find({key:from}) | subtasks | dump(2) }}

    (note that "clones" here is the name of the reverse direction of the "is cloned by" link type used above).

  7. Select "Iterator returns JSON" option

  8. Click on "Add"

  9. Publish the workflow
    1. Select the destination project from in "Project"

    2. Select the "Issue type as "Epic" Select the link type as "is cloned byCalculated"

    3. Using the "Set fields of the new section"

      1. Select the "Epic Name" field

      2. Select the "Copy value from current issue" option

    4. Save the post-function.

  10. Clone Stories: Add a "Transition Linked Issues" post-function configured as

    1. Input the transition name as "Clone Stories" (will be created later)

    2. Select the Link type as "is cloned by"

    3. Save the post-function.

  11. Click on "Add"

  12. Publish the workflow

Create "Clone Stories" transition

  1. On the Epic workflow of the destination project (on the same workflow if both Epics share the same workflow), create a transition named "Clone Stories" on the Create transition to the same initial status.

  2. Hide that transition from users by adding a "Hide From User Condition"

Clone Stories: Add the Create issue post-function to the "Clone Stories" transition

  1. Select the Project as "Same as current issue"

  2. Select the "Issue Type" as "Story"

  3. Input the Summary as:

    Code Block
    {{it.fields.summary}}
  4. Select the "Epic Link" field under "Set fields of new issue"

    1. Select "Set field value to" option

    2. Input the following template

      Code Block
      {{issue.key}}
  5. Select "Create Multiple Issues" checkbox under "Multiple issue creation"

  6. In the iterator write the following script:

    Code Block
    {% set from = issue | issueProperty("jmwe-created-from") | field("key") %}
    {{issue | linkedIssues( "clones" ) | find({key:from}) | stories | dump(2) }}

    (note that "clones" here is the name of the reverse direction of the "is cloned by" link type used above).

  7. Select "Iterator returns JSON" option

  8. Click on "Add"

  9. Publish the workflow

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

Cloning an issue and its subtasks

Using the Sequence of post-function post-function you can clone an issue and its subtasks too. Let's assume on the trigger of the transition "Clone now" you want to clone a Parent and its Subtasks to a different project.

    1. and input

      Code Block
      {{ issue.fields.issuetype.name }}
    2. Select the "Link to new issue" as "clones"

    3. Configure the fields

    4. Click on Save

  1. Add another "Create issue" post-function to clone the linked issues

    1. Select the destination project in "Project"

    2. Select the "Issue type" as "Calculated" and input

      Code Block
      {{ it.fields.issuetype.name }}
    3. Select "Multiple issue creation" option and input the following template:

      Code Block
      languagejs
      {{ issue | linkedIssues("blocks",['key']) | length }}
    4. Select “Linked Issues” under “Set fields of new issue”

      1. Select “Set field value to Groovy expression”

      2. Input the following code:

        Code Block
        [
        {
          "type": {"name":"Blocks"},
          "inwardIssue": {"key":"{{transition.context.newIssueKey}}"}
        }
        ]
    5. Save the post-function.

  2. Click on "Save"

  3. Publish the workflow.

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

...

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

Using the 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.

...

  • Add linking information to the above array as shown below with the "Iterator returns JSON" option selected, 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
    languagejs
    [
    {% if it.linkTo != null %}
    {
      "type": {"name":"{{it.linkTypeName}}"},
      "{{it.direction}}Issue": {"key":"{{newIssueKeys[it.linkTo]}}"}
    }
    {% endif %}
    ]

...

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 of the issue to check that there is no issue created already by the post-function. Select the conditional execution section and input the template:

...

  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
    {{ not issue.fields.issuetype.subtask }}
  2. In the second example, identify the main issue by its issue type as follows. 

    Code Block
    languagejs
    {{ issue.fields.issuetype.name == "Story" }}
  3. 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
    languagejs
    {{ issue | issueProperty("jmwe-created-from") == null }}

...