Jira Automation - Look for existing issue and comment
Asked by Anderson Sato:

Hi there,

We have a simple automation rule that creates a ticket whenever we receive the incoming webhook. The problem is that sometimes we receive updates from the same subject through the webhook.

So, I was willing to perform a quick lookup on the created issues and instead of creating a new issue, comment on the existing one.

Knowing that the summary will be the same, I think I can achieve that.

I was trying to perform a JQL lookup and then use if conditions in case {{lookupissues.size}} was not equal 0, but I can't figure it out how to post the comment in the results of the JQL lookup.

This is the current automation rule

![LHr8RsJQ8K.png](/t5/image/serverpage/image-id/313311i17091D55DC1D90F5/image-size/large?v=v2&px=999 "LHr8RsJQ8K.png")

I thought this would be the end result, but I can't figure out how to add the comments from the list of issues of the \`lookup issues\` component.

![rrHjJh5GrE.png](/t5/image/serverpage/image-id/313320iB9D1209D33EA8571/image-size/large?v=v2&px=999 "rrHjJh5GrE.png")

Any advice?


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

It looks like you're on the right track. While the lookup issues action will get you the ability to find whether a duplicate exists, you ultimately need to branch into the duplicate. So under your Else you'll want to add a Branch based upon the same JQL as your lookup issues JQL to iterate through the duplicate issues. Then you can include your Add Comment action within the branch.

comments: author: Anderson Sato
body: Hi [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) , thanks for assisting me on that.

I'm actually having a hard time on the branch. When you say that I would need to branch into the duplicate would be something like that?

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

I don't quite get why I need to specify the smart value and then declare a variable. I'm quite new in Jira Automation, so apologies if that is some basic concept.

Or what you actually say is to do the following?

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


author: Mark Segall
body: It's the second approach. You're branching into the issue(s) that share the same summary as your webhook trigger. I say "iterate" because the branch will work for one or many summary matches.


author: Anderson Sato
body: Nice, I will update the rule and once I validate it works I will accept your answer. Thanks!


author: Anderson Sato
body: Thanks [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) it worked. I needed to tweak a little my JQL as it contained some special characters, but all seems to be working.


author: Anderson Sato
body: Hey [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) so it seems that I'm still missing something. Sorry to bother you again.

My initial **if** condition was not working properly so I've made some changes to fix it with no success.

The comparison of smart value **{{lookupissues.size}}** is not working and I don't know why. As you can see below from the rule and logs, the **{{lookupissues.size}}** is **1** , but instead of executing the **if** block it executes the **else** . I've tried to change the condition to **not equal** **0,** but then it always executes the **if** block.

![Jira-Automation.png](https://community.atlassian.com/t5/image/serverpage/image-id/321453iCEB1280B3E0CDEC3/image-size/large?v=v2&px=999 "Jira-Automation.png")![Jira-Automation-2.png](https://community.atlassian.com/t5/image/serverpage/image-id/321452iA8DFCBCB11BF3705/image-size/large?v=v2&px=999 "Jira-Automation-2.png")


author: Mark Segall
body: Hi [@Anderson Sato](/t5/user/viewprofilepage/user-id/5457454) - Very interesting. Everything looks correct. The only thing I see is that the condition is not following the same case as the log action (lookup**I** ssues vs lookup**i** ssues. This should not matter, but try using the same case in your condition as you're using in your log action with **I** capitalized.

If this makes no difference (as I suspect it shouldn't), perhaps try forcing it to treat the value as a number (again... something that shouldn't be required) using this:

```
{{lookupIssues.size.asNumber}}
```

Hopefully one of these solves the issue, but from what you shared these extra steps shouldn't be required.


author: Anderson Sato
body: Thanks for the quick reply [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) , I will try that.

I appreciate your help.


author: Kalyan Sattaluri
body: Good call [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) lookupIssues is case sensitive. lookupissues will not work.


author: Anderson Sato
body: Hi guys,

Sorry for my absence on the subject. It seems that even modifying the condition to be case sensitive and forcing the interpretation as a number, it still doesn't work.

I have seen this case where it was suggested to add

```
{{lookupIssues.size|0}}
```

The "size\|0" adds a default value of zero when no issues match the JQL for the lookup. If that's the case I will need to change my if-else block.

<https://community.atlassian.com/t5/Jira-questions/Using-the-lookupIssues-to-find-number-of-issues-in-an-Epic/qaq-p/1681084>

Any other thoughts?

![dSawT5WFOt.png](https://community.atlassian.com/t5/image/serverpage/image-id/323977iE36B78D23DEA0D80/image-size/large?v=v2&px=999 "dSawT5WFOt.png")![jBxt8nUgVZ.png](https://community.atlassian.com/t5/image/serverpage/image-id/323978iC5BFF3613E71598F/image-size/large?v=v2&px=999 "jBxt8nUgVZ.png")


author: Elmedin Jasic
body: Hi  

I'm working on something similar and while trying to branch the issues and drop a comment, I got an error saying:  
Error searching for related issues. This is most likely because the following issues don't have a related issue of the type you specified.

What exactly does it mean 'related issues'?  
Do the issues have to be linked or something like that?

I've also tried a different approach - advanced branching with lookupIssues.key as the smart value, but that fails as well with the error:

Error adding comment to issue

Issue does not exist or you do not have permission to see it.

Any help is appreciated.

<br />

EDIT:  
Using just lookupIssues in the advanced branching option kinda works, but instead of commenting on all the tickets it found, it left as many comments on the trigger issue as it found tickets which isn't super useful for my case


author: Anderson Sato
body: Just a quick followup on this. I managed to find a workaround using regex. I still don't understand why it didn't work with previous conditions.

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

[@Elmedin Jasic](/t5/user/viewprofilepage/user-id/5503524), sorry to not reply you earlier, but I felt that I did not have the knowledge to help you. Yet if you want, elaborate a little more your automation rule and I will try to assist you better.


author: Kalyan Sattaluri
body: Hello [@Anderson Sato](/t5/user/viewprofilepage/user-id/5457454)

In your trigger of incoming webhook, do a JQL search with same criteria as you have in lookup JQL. Then in your Else condition, you can edit that issue and put your comment.

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

comments: author: Anderson Sato
body: Hi [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) ,

In this scenario I'm performing a lookup direcly in the trigger, is that it? I actually use the webook smart value to look for the issue summary. Without it I can't do the JQL lookup.

I tried to see the documentation on this option, but I couldn't find any.


author: Kalyan Sattaluri
body: No, my suggestion was to do JQL in trigger "in addition" to doing your lookupIssues JQL.

BTW, Just FYI - You can directly reference webhook smartvalue in JQL. You dont need intermediate variable called {{summary}}.

I think [@Mark Segall](/t5/user/viewprofilepage/user-id/4666637) suggestion should also work so thats another approach.


Tags: cloud

jira-service-management

jira-service-management-cloud