Automatically Link Tickets Generated from Scheduler
Asked by Dan Schetley:

Hello,

I'm hoping we're just over thinking this, and there's an easy answer, but we currently have 60+ JIRA stories in a Kanban project created by the Scheduler on the first of each month. What we're trying to do is migrate those stories to the Scheduler in a JIRA Work Management board and automatically link them through an Automation since the tickets have dependencies on each other (can be one to one, or one to many dependencies). This way the progression will show up in the Timeline tab of JIRA Work Management. Below are examples of the ticket structure:

- Ticket A is dependent on B being completed and A should be blocked by B

- Ticket D is dependent on B and C being completed and D should be blocked by B and C

The goal is to try to avoid someone needing to manually go in and link the tickets in the JIRA Work Management board.


Answers:
author: Bill Sheboy
body: Hi [@Dan Schetley](/t5/user/viewprofilepage/user-id/1485201)

Regardless of the way the issues are created, an automation rule would need guidance for the linking.

If you are creating these with a scheduled trigger automation rule, the linking could probably occur there, either through absolute (e.g., a specific key and link type) or relative linking (e.g., link to the last issue created in the rule).

Kind regards,  
Bill

comments: author: Joe Tobey
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) I was working to help [@Dan Schetley](/t5/user/viewprofilepage/user-id/1485201) with this and I was getting stuck on the relative linking related to the "last issue created". It kept trying to reference itself. For example:

Automation Creates Issue1 then Issue2. When I use the relative linking, it sees Issue2 as the "Last Issue Created" and errors out as it cannot reference itself. any thoughts for getting around that?


author: Bill Sheboy
body: Hi [@Joe Tobey](/t5/user/viewprofilepage/user-id/2007364)

There are a couple of solutions for that...

First, as issues are created *in the main execution path of the rule*, two smart values are available: {{createdIssue}} and {{createdIssues}} (note the plural). With the second one any of the previously created issues could be referenced using the get() function in the list, with {{createdIssues.get(n)}} where n is a 0-based index for the issues. And so the first one is 0, and the key is {{createdIssues.get(0).key}}

That method breaks down if the issues are created either inside of an if/else structure or a branch, due to scoping issues. (There is sometimes a work-around for that, using the method below.)

The second method is to save the {{createdIssue.key}} with the Create Variable action after the issue is created. This method is often used when cloning a tree of issues, like the epic and its children.

Kind regards,  
Bill


author: Dan Schetley
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Thanks for the quick responses. Would it be possible to send an example automation for my example above:

Ticket D is dependent on B and C being completed and D should be blocked by B and C

I think if we could get that then we can build upon it from there.

Thanks,

Dan


author: Bill Sheboy
body: The only tricky part about a rule like this is setting the issue links: *when you type in the smart value, it appears below the field, and then it can be selected for use to link the issues.*

Here's an example rule. The links must be added one at a time, due to limitations in the rule actions (and supporting REST API functions).

* trigger: manual
* action: create issue-B
* action: create issue-C
* action: create issue-D
  * select the Linked Issues field, and enter the following to link to issue-B
    * is blocked by
    * {{createdIssues.get(0).key}}
* branch: to most recently created issue, which is D
  * action: edit issue, select the Linked Issues field, and enter the following to link to issue-C
    * is blocked by
    * {{createdIssues.get(1).key}}

Please try that first to confirm it works as you expect, and then expand for the remainder of your scenario.


author: Joe Tobey
body: This works great with some slight modification.


author: Bill Sheboy
body: I am glad to learn that helped. Please consider marking this question as "answered", as that will help others in the community with similar needs find solutions faster. Thanks!