How do I create an automation to link issues together with the same label?
Asked by Brian Alves:

I am trying to link issues with the same label.   

So if I create 10 issues with the label "test" I'd like to run a rule to link them.   

This is the automation I'm working with and not getting any success :( ![Screenshot 2024-08-05 at 11.28.09?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340085i7CA93613A928E93B/image-size/large?v=v2&px=999 "Screenshot 2024-08-05 at 11.28.09?AM.png")th right now and have not had any success  

<br />


Answers:
author: Trudy Claspill
body: Hello [@Brian Alves](/t5/user/viewprofilepage/user-id/5555879)

Welcome to the Atlassian community.

What event do you want to trigger this rule? Do you want it to be triggered each time a new issue is created, then have it find all the other issues with the same label as the trigger issue, and link the trigger issue to all the issues found?

Do you want to trigger the rule after all 10 issues have been created? And then create a link between each of those 10 issues and all the other 9 issues in the set (so each of the 10 issues has links to 9 other issues)?

An issue can have more than one value in the Labels field. How is your rule going to know the relevant Label value?

Do you want to be able to run this rule for different label values?

comments: author: Brian Alves
body: Hi [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011) !   

Yes I would like to run on every issue and group specific labels with each other. I'm hoping to have multiple labels then create a rule for each label to link with eachother.   

If I create an initiative with 10 items in it and 2 labels. So 5 items would have label 'test' the other 5 would have label 'test2' then the automation would link issues with the same label together. Not necessarily to any trigger issue.   

Does that make sense?


author: Trudy Claspill
body: I am still not clear on when you want the rule to trigger.

Let us say it is triggered upon the creation of a single issue. And that issue may have 0..n Labels values.

I think this is the type of flow you're looking for. Correct me if I'm wrong.

```
When issue created
And Labels is not empty
For each Labels value
? Find other issues that have the same Labels value
? ? For each issue found
? ? ? Link that issue to the rule's trigger issue.
```

Unfortunately Automation Rules don't support nesting For branches in that manner.

Are you trying to incorporate this linking into an Automation Rule where you are also creating the Initiative and the child issues? Or is the issue creation being done manually?

Might you create more issues with the same Labels that you used previously ('test' and 'test2')? Should those new issues be linked to the ones created before?


author: Brian Alves
body: ah okay so I will keep this simple

If I create issues that share the same label I want to them to automatically linked to one another based on label. So if I create 10 issues with 1 label in each of those issues then they should all connect to one another.

When issue created  
Label = test  
Link to one another with label


author: Trudy Claspill
body: So you want this triggered when an issue is created?

And you are willing to hard-code the label value into the rule?

In that case the flow would be:

```
When Issue Created
And Labels in ("test")
For Related Issues / JQL
  JQL: key != {{triggerIssue.key}} and Labels in ("test")
    Link issues
      link to Trigger Issue
```

![Screenshot 2024-08-06 at 2.33.48?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340365i83C05C9FD74501A7/image-dimensions/311x403?v=v2 "Screenshot 2024-08-06 at 2.33.48?PM.png")

![Screenshot 2024-08-06 at 2.33.58?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340366i824D984F87A575FB/image-dimensions/401x324?v=v2 "Screenshot 2024-08-06 at 2.33.58?PM.png")

![Screenshot 2024-08-06 at 2.34.12?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340364iD3EA8C3DD4121825/image-dimensions/341x337?v=v2 "Screenshot 2024-08-06 at 2.34.12?PM.png")

![Screenshot 2024-08-06 at 2.34.21?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340363i8D60C625B08F2802/image-dimensions/411x213?v=v2 "Screenshot 2024-08-06 at 2.34.21?PM.png")


author: Brian Alves
body: Thank you! The first part is great, but I'm still having a tough time linking every item to one another.   

So Task1, task 2, task 3, task4 and task5 are created

task 1 should be linked to t2 t3 t4 t5

task 2 should be linked to t1 t3 t4 t5

task 3 should be linked to t1 t2 t4 t5

task 4 should be linked to t1 t2 t3 t5

task 5 should be linked to t1 t2 t3 t4


author: Trudy Claspill
body: Since the rule is run as each issue is created, and if they are created in the order of t1 through t5...

The rule will trigger when t1 is created. There will be no issues to link to at that point.

The rule will trigger when t2 is created. At that point there is only t1 that matches, so t1 will be linked to t2.

The rule will be triggered when t3 is created. At that point t1 and t2 match, so t3 will be linked to each of them.

At this point t1 is linked to t2 and t3. t2 is linked to t1 and t3. t3 is linked to t1 and t2

The rule is triggered when t4 is created. t1, t2, and t3 match, so t4 will be linked to all of them

The rule is triggered when t5 is created. t1, t2, t3, and t4 match, so t5 will be linked to all of them.

In the end after the rule runs for each newly created issue, they will all be linked to each other.


author: Brian Alves
body: Ahhh I'm not getting that it's only linking to the trigger issue. But I am utilizing another automation to create the tickets, does tha tmake a difference?   

Currently I am creating a task  
if task is created the create subtasks  
subtasks have these labels which is where I need the linking done


author: Trudy Claspill
body: I think I asked you about that...
> Are you trying to incorporate this linking into an Automation Rule where you are also creating the Initiative and the child issues? Or is the issue creation being done manually?

If you want to try to incorporate this into another rule where you are creating the issues then please show us that complete rule.

Keeping the linking rule as a separate rule should work. However there may end up being timing issues. I recommend that you do a limited run test to see how it works out.

Given that these are subtasks that have the labels you can enhance the rules in some additional ways.

* After the trigger add a condition to check if the Issue Type is Sub-task.
* Within the JQL in the Lookup Issues action add conditions:
  * AND issueType in subtaskIssueTypes() and parent = "{{triggerIssue.parent.key}}"

Also, if you keep this as a separate rule there is a checkbox on the Rule Details page that you will have to check to allow the linking rule to be triggered by the creation of issues in another rule.

![Screenshot 2024-08-06 at 3.57.03?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/340388iCE47C094E9D3A434/image-size/large?v=v2&px=999 "Screenshot 2024-08-06 at 3.57.03?PM.png")


author: Brian Alves
body: Ah sorry I missed that. You did it! Thank you so much.

Last question for you, can I create a condition in JQL where it's only created today?


author: Trudy Claspill
body: Yes, you can.

Add this

AND created \> startOfDay()


author: Trudy Claspill
body: You can learn more about functions, keywords, and fields you can use in JQL here

<https://support.atlassian.com/jira-software-cloud/docs/what-is-advanced-search-in-jira-cloud/>


author: Trudy Claspill
body: If my responses have helped you solve your requirement please consider clicking the Accept Answer button to mark your post as Solved.


author: Samuel Gatica
body: Hi [@Brian Alves](/t5/user/viewprofilepage/user-id/5555879)

Welcome to the comunity!

You need to create a new branch to investigate the issue with the same labels, after which you can link the newly created issue with the others.

i.e

![Screenshot_1.png](https://community.atlassian.com/t5/image/serverpage/image-id/340091i142F0B49D4419602/image-size/large?v=v2&px=999 "Screenshot_1.png")

Hope this helps!

Best regards

Sam

comments: author: Trudy Claspill
body: That assumes that the issue created (the trigger issue) has the value "test" in its Labels.


author: Brian Alves
body: Hi [@Samuel Gatica](/t5/user/viewprofilepage/user-id/753028) !   

I would like to run on every issue and group specific labels with each other. I'm hoping to have multiple labels then create a rule for each label to link with eachother.   

If I create an initiative with 10 items in it and 2 labels. So 5 items would have label 'test' the other 5 would have label 'test2' then the automation would link issues with the same label together. Not necessarily to any trigger issue.


Tags: cloud

jira-cloud