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)
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem Jordan, good work...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For you other question, I'm using v0.5.0 of the Behaviours plugin.
Cheers again,
Jordan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Jamie
can i use the auto dupes to monitor some customfield value instead of sumarry field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.