Script Runner check for existing issue

Daniel Wong March 30, 2014

Hi I'm trying to use Groovy Runner to create an issue as part of a Post Function. However, before the post-function creates the issue, I'd like to run a search and check for existing issues with the same Summary or matching custom fields, and if found, link to that issue instead of creating a new issue.

I can't seem to find out how to do the jira search part of the script. I could probably do a JQL search in the GUI but I don't know how to translate that into script code. Any suggestions?

2 answers

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2014

You are going to have trouble bailing out of the "create" process from a post-function.

Maybe try doing it in a validator...?

There is some code for the behaviours plugin here: http://blogs.onresolve.com/2010/03/audo-duplicate-search-in-jira/- but you could get what you want out of it. Or use Boris' example.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 31, 2014

What do you actually mean by "and if found, link to that issue instead of creating a new issue"? You mean create the issue and link, or not create the issue, and link what?

Daniel Wong March 31, 2014

Problem is, I need it to be automated rather than a message popping up asking the user to close and link manually.

I'll give Boris' code a go or might have to think of an alternative to this :S

Daniel Wong March 31, 2014
  • Search for issue
  • If there is an existing issue with matching fields/summary:
    • Link Matching Issue to current issue
  • Else:
    • Create New Issue and Link to current issue

So I just want to save that extra step of creating new issues and getting lots of duplicates

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2014

Here's a Java sample and you'll have to just port it to groovy:

final JqlQueryBuilder queryBuilder = JqlQueryBuilder.newBuilder();
		final JqlClauseBuilder whereBuilder = queryBuilder.where().defaultAnd();
		whereBuilder.summary().like("some summary")
		Query query = queryBuilder.buildQuery();
		User user;
		SearchResults results = ComponentAccessor.getComponent(SearchProvider.class).search(query, user, PagerFilter.getUnlimitedFilter());
		List<Issue> issues = results.getIssues();

Daniel Wong March 31, 2014

Thanks I'll give this a try in groovy

Suggest an answer

Log in or Sign up to answer