Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,564
Community Members
 
Community Events
184
Community Groups

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

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

0 votes
Tansu Akdeniz
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 04, 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
TAGS
AUG Leaders

Atlassian Community Events