Comment and Link older Keys in "LookupIssues" results
Asked by Tiago Leite:

Hi!  

I have an automation that runs a ***{{lookupIssue.key}}*** that usually returns a set of 2 or 3 results. Example: run on the ++A1++ issue \>\> returns ++A2++ , ++A36++ and ++A87++   

From those results, I want the automation to change the status of the two newer results, ++A36++ and ++A87++ to a specific status and the oldest one, ++A2++ , to another. How can I do that?  

Also, from that list, how can I comment and link the results found like this:

**On issue A1:** "++A2++ , ++A36++ and ++A87"++   
**On issue A2:** "++A1++ , ++A36++ and ++A87"++   
**On issue A36:** "++A1++ , ++A2++ and ++A87"++   
**On issue A87:** "++A1++ , ++A2++ and ++A36"++ Right now, I can only comment and link the issue A1 with the issues "A2, A36 and A87", but not the results the Lookupissue finds. How can I do that?  

Thank you for your help! ?


Answers:
author: Mark Segall
body: Hi [@Tiago Leite](/t5/user/viewprofilepage/user-id/4883764) and welcome to the community!

It would help if you could share a screenshot of your rule so we can get a little more context of what you're trying to accomplish.

Without that additional context, I'm not even sure the lookup issues action is required. Based purely on what you shared, you could accomplish this with two branch rules... One based upon a query that returns the "newer" issues and the second pulling in the older issues. Then perform the transitions within each branch.

comments: author: Tiago Leite
body: Hi [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) ! Thank you for your reply!  

Here's the first phase of this search, just before the comment + link on the results found on the "lookupissues" keys.  

I'm able to change those results to "Investigation in Progress" and assign them, but I can't find a way to comment and link them individually with the rest of the results and the trigger issue (referred as A1 on this post).   

![Screenshot 2022-04-19 14.24.10.png](https://community.atlassian.com/t5/image/serverpage/image-id/193487i3B3EB20CF957B357/image-size/large?v=v2&px=999 "Screenshot 2022-04-19 14.24.10.png")


author: Mark Segall
body: So if I'm understanding correctly, you're attempting to identify when an issue is created whether it is a duplicate and then close if true. Is this correct?

I'm not following your intent behind the branch rule. It appears that you're trying to transition any issues with similar description to "Investigation In Progress" and assign to the user who triggered the event.


author: Tiago Leite
body: That's it! It basically looks for duplicates and closes them as "Duplicate tickets".  

What I want is to leave the oldest one that it could find on the "lookupissue" in "Investigation in Progress" but for that, I need to order those results from oldest to newest. The other tickets can be closed as "Duplicates" too, only the oldest one matters.  

In addition to that, if there's 4 tickets, I want them linked to each other:  

A1 \>\> linked to A2, A3, A4  
A2 \>\> linked to A1, A3, A4  
A3 \>\> linked to ...


author: Mark Segall
body: ok - So I would do a couple things here:

1. Update your Lookup Issues action so that the query looks something like this:
   1.

      ```
      summary ~ "{{issue.summary}}" AND Key = {{issue}} ORDER BY Key ASC
      ```

2. Create a variable like this to capture the first issue:
   1.

      ```
      {{lookupIssues.get(0).key}}
      ```

3. Perform an advanced branch against {{lookupIssues}}
4. Perform your linking inside the advanced branch
5. Add an advanced condition inside the branch where your branch variable equals your oldest variable
6. Add an issue transition after the advanced condition


Tags: comment

issue-link

link