Found AutoDupes.groovy script to detect duplicate issues, but only works when creating issues not editing

Hello,

I came across this script while looking for a free alternative to Suggestimate and it works perfectly when creating new issues (shows the top matches for the Summary field to help reduce duplicate tickets) however I'm getting errors in the log and no results returned when editing an issue.

Probably should note that it relies on the Behaviours plugin to function.

The script that I found from http://blogs.onresolve.com/?p=123, all credit to Jamie Echlin who originally "grooved" it up.

My question, I am not quite a groovy programmer, but was hoping it would be a simple fix to have it work both when creating issues as well as editing them. What is null when editing an issue that is not null when creating an issue? Something to do with clauseValues if that helps.

The error in the logs:

2012-09-06 13:22:42,135 http-8443-85 ERROR username 802x88429x1 1msl8i1 ###.###.###.###,###.###.###.### /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with  method getPossibleDupes in class /data/jira/scripts/AutoDupes.groovy

com.atlassian.jira.util.dbc.Assertions$NullArgumentException: clauseValues should not be null!

        at com.atlassian.jira.util.dbc.Assertions.notNull(Assertions.java:26)

        at com.atlassian.jira.util.dbc.Assertions.containsNoNulls(Assertions.java:87)

        at com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.addNumberCondition(DefaultJqlClauseBuilder.java:943)

        at com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.addNumberCondition(DefaultJqlClauseBuilder.java:914)

        at com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.project(DefaultJqlClauseBuilder.java:334)

3 answers

1 accepted

Hey...

I think the pid (project ID) is null when editing (not tested though).

Try inserting the following directly under this line: "Long pid = getFieldById("pid").getFormValue() as Long" (line 27).

if (!pid) {
            pid = underlyingIssue.projectObject.id
        }

The whole thing is here: https://gist.github.com/3705569

Hey Jamie,

First of all cheers for such a quick reply! Also the script you wrote is brilliant, thank you for having that out there as well!

I tried adding the code above (and verified I had inserted it into the correct spot by checking with the script you referred to, but unforutnately am getting the following error:

[onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with method getPossibleDupes in class /data/jira/scripts/AutoDupes.groovy

java.lang.NullPointerException: Cannot get property 'projectObject' on null object

To confirm it was the project Id that was null I added the snippet below (in place of underlyingIssue.projectObject.id) and results came up as expected.

pid = 10001

I tried various snippets of code that I found via google to determine the project Id to no avail.

I should add that I am running JIRA 4.4.5 if that changes anything?

Thanks again for the help so far,

Cheers,

Jordan

No worries. What version of the behaviours plugin do you have? There was an issue whereby getUnderlyingIssue() was not always working in previous versions.

What you need to do is, if the pid is null, get the issue id:

getFieldById("id").getFormValue()asLong

Then use IssueManager to get the issue, and from that get the pid.

So can you confirm anyway that the pid is null when editing an issue, and that the id is not null?

Thank you very much Jamie, I got it going!

Added the following code to your script:

import com.atlassian.jira.issue.IssueManager

&

Long iid = getFieldById("id").getFormValue() as Long

if (!pid) {

if (!iid) {

// Oh no!

} else {

IssueManager issueMgr = ComponentManager.getInstance().getIssueManager()

issue = issueMgr.getIssueObject(iid)

pid = issue.projectId

}

}

Thanks again for your guidance, and in answer to your question:

The pid is null when editing an issue, as when I manually set the pid the script worked when editing the issue (I entered pid = 10001).

The issue id is not null, else my "// Oh no!" would have come into play during my testing.

Cheers again,

Jordan

No problem Jordan, good work...

For you other question, I'm using v0.5.0 of the Behaviours plugin.

Cheers again,

Jordan

I had one more question about this script, I've had a good go at writing this myself but cannot get my head around adding an orderby clause to the query.

I would like to sort by project as I've customised this script to search the current project plus a repository project with precedence given to results from the repository.

It appears to be similar to this:
ordered = query.orderBy().project(ASC).endOrderBy().buildOrderBy()
and I'm importing this:
import com.atlassian.jira.jql.builder.JqlOrderByBuilder

The error:

2012-12-05 15:29:28,312 http-8080-5 ERROR jordan 929x4496x1 mc4v7a 192.168.0.131 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with method getPossibleDupes in class /data/jira/scripts/AutoDupes.groovy

groovy.lang.MissingMethodException: No signature of method: com.atlassian.query.QueryImpl.orderBy() is applicable for argument types: () values: []

Possible solutions: every(), every(groovy.lang.Closure), grep()

I'm happy to open a new thread too but as it relates to this script thought it best post here.

Any help would be appreciated,
Cheers,

Jordan

It would be best to open a new question... it relates to the script but is not about the script. Simply because you're going to get more views in a new question. I don't see getOrderBy() in https://developer.atlassian.com/static/javadoc/jira/5.2/reference/com/atlassian/query/Query.html.

Cheers Jamie, will do. Thanks as always,

Jordan

hi @Jamie

can i use the auto dupes to monitor some customfield value instead of sumarry field ?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,383 views 0 8
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