check for issue duplicates

Story:
"As a user i will get an Information that an issue already exists when i create a new issue and enter the material number in a custom field"

I thought that i can solve this via script in the behaviour plug-in, this is my attempt but it does not work:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.web.bean.PagerFilter;
import org.apache.log4j.Logger;
import org.apache.log4j.Category;
// Create Log for Level DEBUG
def Category log = Category.getInstance("com.onresolve.jira.groovy");
log.setLevel(org.apache.log4j.Level.DEBUG);
// Get Information about Material No
def material = getFieldById(getFieldChanged())
// Search for issues with same Material No
String jql = 'project = MAT AND resolution = Unresolved AND Material IN ("' + material + '")';
// Get a search-Object
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
// For JIRA 7.X must be ApplicationUser, doesn't work in 6.X
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
List<Issue>issues = null;
SearchService.ParseResult parseResult =  searchService.parseQuery(user, jql);
if (parseResult.isValid()) {
    issues = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()).getIssues();
} else {
    // JQL couldn't be parsed, show Error
    log.debug("Invalid JQL: " + jql);
    material.setHelpText("Invalid JQL: " + jql);
}
// Check for other Issues
if(issues.size()>=1){
    // We have another Issue
    issues.each{
        // For Debugging Purposes log the Issue Key of the other issues
        log.debug("Other Issue (" + it.getKey() + ") dealing with same Material!");
        material.setHelpText ("Issue is duplicated by (" + it.getKey() + ")")
    }
}

Is this apporach wrong? Does anyone have a solution?
Buying another plugin is no solution ;-)

1 answer

0 vote
Alexey Matveev Community Champion Nov 29, 2017

Hello,

Could you give more infromation on the error. What exactly does not work?

I can`t see anything in the log or on the create issue screen.

 

I`m wondering if someone has a working solution for the Story.  

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

148 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you