How can I create multiple epics each with their own tasks associated in one rule?
Asked by Julia:

I want to create an automation that does the following

1. Create Epic 1 with parent link as Initiative 1

* Task with Epic 1 as parent

2. Create Epic 2 with parent link as Initiative 1

* Task with Epic 2 as parent

3. Create Epic 3 with parent link as Initiative 1

* Task with Epic 3 as parent

I already know how to make the Epics \& correctly link them to the initiative by using:

{  
"fields": {  
"Parent Link": "{{triggerissue.key}}"  
}  
}

How can I make the Tasks have their Epic Links be as defined above?


Answers:
author: Julia
body: I ended up creating three rules. One to create the 2 epics and the following two to make tasks for each of those epics.


author: Mykenna Cepek
body: Just create the first Epic, and save that issue off in a variable from the {{createdIssue}} smart value:

<https://support.atlassian.com/jira-software-cloud/docs/smart-values-general/#Smartvaluesgeneral---createdIssue-->

Then create the first Task under that Epic, and use the saved variable to set the "Epic Link" field. This can be done in the GUI, no JSON needed.

Rinse and repeat!

comments: author: Bill Sheboy
body: Hi [@Mykenna Cepek](/t5/user/viewprofilepage/user-id/3527113) and [@Julia](/t5/user/viewprofilepage/user-id/3416541)

I think that when you add the task, you can just set the "Epic Link" to {{createdIssue.key}} without the created variable, as that will contain the [last created one in the rule](https://support.atlassian.com/jira-software-cloud/docs/smart-values-general/#Smartvaluesgeneral---createdIssue--)...as long as it wasn't inside of a branch.

Kind regards,  
Bill


author: Julia
body: [@Mykenna Cepek](/t5/user/viewprofilepage/user-id/2231007) When you say "save that issue off in a variable" how can I do that? I know how to call {{createdissue}} but how do I do that for each epic and save them uniquely?

@\[deleted\] would that solution confuse the automation since the last created issue for some of the tasks would be a preceding task?

for example:

Epic 1:

* Task 1 with epic link as {{createdIssue.key}} would work fine
* Task 2 with epic link as {{CreatedIssue.key}} would the automation try to use Task 1 since it was created the most recently ?


author: Mykenna Cepek
body: [@Julia](/t5/user/viewprofilepage/user-id/3416541) You're concern about the last created issue being replaced by the most recently created Task is valid. This is why I suggested saving it in a variable.

To create a variable, just use the "Create Variable" action:

<https://support.atlassian.com/jira-software-cloud/docs/automation-actions/#Automationactions-Createvariable>

Basically you just make up a variable name (like "LatestEpic") and fill in {{createdIssue}} for the Smart Value. That variable will hold the value you set.

Then use {{LatestEpic}} when setting the "Epic Link" field for each new Task.

Once you've processed the first Epic and all it's Tasks, then create the second Epic, and use that same "Create Variable" action again (with identical parameters). This will update the variable to relate to the second Epic.

And so on!


author: Julia
body: Oh no! That would work perfectly, but I'm on Jira Server and that option isn't available. Thank you for the suggestion, I wish I could use it.

[@Mykenna Cepek](/t5/user/viewprofilepage/user-id/3527113)


author: Mykenna Cepek
body: Hmm. Ok, plan B...

There is a smart value called {{createdIssues}} -- plural. Apparently it aggregates a list of all the issues created in this rule. So...

Create all the Epics first. At this point, I would expect the {{createdIssues}} smart value to be a list of all those Epics.

Then create each Task, and use a smart value list function to pull out the appropriate Epic from {{createdIssues}} when setting the "Epic Link" field in each Task.

According to the Jira Server docs for Automation and smart value list operations...

<https://confluence.atlassian.com/automation/lists-993924868.html>

...something like {{createdIssues.get(0)}} should return the Epic Link value for your first set of Tasks. Increment the number for each successive Epic.


author: Julia
body: Thank you! Let me try this and let you know if it works.


author: Bill Sheboy
body: Hi, and sorry I am catching up on the thread. :\^)

My understanding of {{createdIssue}} *singular* is that it \*always\* contains the information from the most recently created issue in the rule...With one exception: there is a by-design behavior that this can get "lost" when issues are created in a branch. (Branches of more than one thing fire off independently of the rule, and so there is no guarantee when they finish.)

So, I was proposing a variation of what [@Mykenna Cepek](/t5/user/viewprofilepage/user-id/3527113) noted using {{createdIssues}} *plural*. One at a time would be:

* created an epic
* create a task linked to the most recent epic using {{createdIssue.key}}
* created an epic
* create a task linked to the most recent epic using {{createdIssue.key}}
* ...


author: Mykenna Cepek
body: Totally makes sense, [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313). I had two (unconfirmed) concerns with this approach:

* I assumed a need to (at least sometimes) create multiple Tasks under each Epic. Upon review, that wasn't explicitly stated in the OP. Might end up being a "subtle brittleness" that would misbehave if a second Task was added.
* I wasn't confident about the value of {{createdIssue}} during a "Create Issue" action, and didn't have time to verify that it would be the previously (not currently) created issue.

I think we're both interested in hearing what eventually worked for [@Julia](/t5/user/viewprofilepage/user-id/3416541) !


author: Bill Sheboy
body: Hi [@Julia](/t5/user/viewprofilepage/user-id/3416541)

Just following up to learn if you resolved this one. If so, would you please mark it as answered? That will help others in the future find solutions faster.

Thanks,  
Bill


author: Julia
body: n/a


Tags: cloud