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:

...

Info

Create a sequence

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

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

    1. Select the destination project in "Project"

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

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

    4. Configure the fields

    5. Click on Save

  3. 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.

  4. Click on "Save"

  5. Publish the workflow.

Now when you trigger the transition "Clone now" the Parent and its subtasks 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.

Info

Create a sequence

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

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

    1. Select the destination project in "Project"

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

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

    4. Configure the fields

    5. Click on Save

  3. Add another "Create issue" post-function to clone the sub-tasks

    1. Select the destination project in "Project"

    2. Select the "Issue type" as "Subtask"

    3. Under the "Parent issue" input the following template:

      Code Block
      languagejs
      {{ transition.context.newIssueKey }}
    4. Select "Multiple issue creation" option and input the following template:

      Code Block
      languagejs
      {{ issue | subtasks | length }}
    5. Save the post-function.

  4. Click on "Save"

  5. Publish the workflow.

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

Link newly created issues

...

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 }}

...