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

jordan help September 11, 2012

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

1 vote
Answer accepted
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.
September 11, 2012

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

jordan help September 12, 2012

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

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.
September 12, 2012

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?

jordan help September 13, 2012

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

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.
September 13, 2012

No problem Jordan, good work...

jordan help September 13, 2012

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

Cheers again,

Jordan

0 votes
Dinesh Dhinakaran
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 10, 2014

hi @Jamie

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

0 votes
jordan help December 4, 2012

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

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.
December 4, 2012

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.

jordan help December 5, 2012

Cheers Jamie, will do. Thanks as always,

Jordan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events