Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

summary should not be same as existing issue in jira using groovy(post function/validator)

Vruti Thakkar April 4, 2023
I've been working on this issue where Jira should give an error during ticket creation if the same summary exists in the Jira project.
I tried the below code where I get the list of summaries and the current summary. here I also want to compare the same. 
It would be great if anyone is up here to help me in this regard.
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue

 

def groupManager = ComponentAccessor.getGroupManager()
// Get the issue manager
IssueManager issueManager = ComponentAccessor.getIssueManager()

 

// Get the summary of the issue being created
def summary = issue.getSummary()

 

def searchService = ComponentAccessor.getComponentOfType(SearchService)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

 

def filter = "Project = TDT"
SearchService.ParseResult parseResult = searchService.parseQuery(user, filter)
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)

 

//def issues = results.issues //Jira 7
def issues = results.results //Jira 8
issues.each { it ->

 

    log.debug(it.summary)

 

}

1 answer

1 vote
Tansu Akdeniz
Community Champion
April 4, 2023

Hi @Vruti Thakkar 

In this line, you search all issues in TDT project.

def filter = "Project = TDT"

You can change like this. Then, you could look at the results size to see if there is any match.

def filter = "Project = TDT and summary ~ $summary"

BUT, searching exact string is not possible and you would probably face problems with this query. There is a ticket for exact-text searching in JQL JRASERVER-21372.

There is also the following function (comes with an add-on) which may allow you do exact search:

issueFunction in issueFieldExactMatch(subquery, fieldname, regexp)

Please take a look at this thread.

Suggest an answer

Log in or Sign up to answer