Check if linked issues contain EXACT summary match
Asked by Chris Rosendorf:

Hello, I am using the **Automation Rules** in **Jira Cloud** , and trying to solve a "classic": "if issue with summary does not exist, create it".  

I have made an automation down to the point where I have these following things available to me:  

1) A list of linked issues: {{lookupIssues}}.

2) A {{summaryName}} variable.

I now would like to know how to go about checking if the linked issues list contains an EXACT MATCH of the {{summaryName}} variable.

Using the: "summary \~ "\\"{{summaryName}}\\"" does not provide an exact match, as I have other issues that might contain the summaryName, but also include more.

(E.g. TEST-7 has the summary: "Test Issue", TEST-8 has the summary: "Test Issue2")

I have already tried branching for each of the {{lookupIssues}}, and checking:  

\`\`\`  
If: Compare two values  
{{lookupIssue.summary}}  
equals  
{{summaryName}}  
\`\`\`  

But I am unsure how to continue, because I need to exhaust the checking of the list, before I know if the summary is an exact match, and thus continue.  
(I tried setting a variable value if a match was found, but seems like it isn't available after the branching scope? Or perhaps I am using it wrong)

P.S I am surprised that a text field (Summary) does not allow the '=' operator to check for exact matches.


Answers:
author: Rilwan Ahmed
body: Hi [@Chris Rosendorf](/t5/user/viewprofilepage/user-id/3399702) ,

Welcome to the community !!

Unfortunately at present jira does not support "**=**" for text search. There is already a feature request and you can vote and watch for the updates.

<https://jira.atlassian.com/browse/JRACLOUD-81881>

comments: author: Chris Rosendorf
body: Thank you, I think this is a pretty core feature that's missing, and one that doesn't seem very difficult to actually implement...

Regardless, I've accepted that it doesn't exist, but just want to find a work-around that's available to me. I saw that a work-around is utilising ScriptRunner, can I do this in the Jira Cloud Automation environment, and if so, could you perhaps help me with it?  

```
issueFunction in issueFieldExactMatch(subquery, fieldName, regularExpression)
```

<br />

issueFunction in issueFieldExactMatch("issue in linkedIssues({{triggerIssue.id}})", "summary","\^{{summaryName}}$")  

Would something like that work? And can I just write that, or do I need to be under a ScriptRunner tab, for it to work?


author: Rilwan Ahmed
body: Hi [@Chris Rosendorf](/t5/user/viewprofilepage/user-id/3399702) ,

You need to have the [scriptrunner](https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?tab=overview&hosting=cloud) plugin installed in your jira.

**Syntax**:

    issueFieldExactMatch (subquery, fieldname, regexp)

**Example** :   
issueFunction in issueFieldExactMatch("project = ABCD", "summary", "Test")

Official documentation is in <https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions/match-functions>


author: Chris Rosendorf
body: We have ScriptRunner for Jira, I can see it in the "Apps" tab, "ScriptRunner Enhanced Search" and "ScriptRunner for Jira", as well as some other apps unrelated to this.

I can't seem to use the issueFunction in issueFieldExactMatch, though:  

There was an error executing a search during custom value definition:  
Field 'issueFunction' does not exist or you do not have permission to view it.

Perhaps you could give me a hint as to where to enable it? :)

Just to re-iterate, I am on **Jira Cloud**, given that, is it still possible?


author: John Funk
body: Hi Chris - Welcome to the Atlassian Community!

What trigger are you using to kickoff the rule?

comments: author: Chris Rosendorf
body: I am using a:  

When: Value changes for Description

To start the process, because that's when I need to check through and start the rule.

Does this impact the way I can search through the linked issues?


author: John Funk
body: Maybe try doing a Branch for Linked Issues (instead of lookupIssues), then under the branch this:

If: Compare two values  
{{triggerIssue.summary}}  
equals  
{{issue.summary}}


author: Chris Rosendorf
body: I need to ensure that NONE of the linked issues matches the summary, and I can't say that index 0 didn't match the summary, so create the issue, but then the 3rd index in the list is an exact match. Also it would create duplicates, if it loops through the linked issues and just checks that.


author: John Funk
body: So you have issues A, B, C linked to Issue D. The description for issue D changes, issue A is a match on the summary but B and C do not. What are you wanting to happen?


author: Chris Rosendorf
body: For that example: Nothing.

When a {{summaryName}} is NOT an exact match for a summary of an issue in the list of linked issues (A, B, C) then create it - (The creation part I've already got working)  

I just want to ensure I don't make duplicates of everything every time something is changed.


author: John Funk
body: Can you share a screenshot of your rule?


author: Chris Rosendorf
body: It's a bit too big to post a screenshot of, and I don't think that will provide much more value than the description I wrote.  

Main thing is: "Create an issue with X summary, if summary with X does not exist".

I have a list of linked issues, so I know what to check through.

I have the summaryName in a variable, so I know what search term I am looking for.

<br />

All I need is the comparison of if {{summaryName}} is not an exact match for an issue's summary in the lookupIssues' list. Which is really hard to do, without an = operator.  

So to recap what I then tried:  

For: branch from linkedIssues

And I can now use a field comparison for "summary equals {{summaryName}}", but if I can't edit a variable, nor access a created variable outside of the branch scope, those also do not give me a way to check if the summary exists in the list by looping through it in a branch.

Perhaps you have a good idea to solve this?


author: Bill Sheboy
body: Hi [@Chris Rosendorf](/t5/user/viewprofilepage/user-id/3399702)

When you have a very long rule to post, you can try a browser addon or separate app to capture the image with the page scrolling.

Back to your question...and without seeing your rule for context...

Rather than branching over the issues you could try:

* use a lookup issues action with JQL to gather them,
* create a variable to represent a regular expression to search for your target Summary value
* use the inline iteration with the [match() function](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--) to identify if any existing issues have the same summary, and then decide your actions

```
{{lookupIssues.summary.match(varYourSearchExpression)}}
```

Kind regards,  
Bill


Tags: automation-rule

cloud