Hi All,
I'm trying to write a groovy script to auto populate number of issues on a JIRA issue filter (just count) to a custom field as part of workflow transition.
Below the sample script,
String jqlSearch = "filter= \"" + demo + "\"";
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService .class);
ParseResult parseResult = searchService.parseQuery(authenticationContext.get LoggedInUser(), jqlSearch);
int totalIssues = 0;
if (parseResult.isValid()) {
try {
SearchResults results = searchService.search(authenticationContext.getLogg edInUser(), parseResult.getQuery(), PagerFilter
.getUnlimitedFilter());
final List issues = results.getIssues();
totalIssues = issues.size();
//add code here to update custom field
MeD = cfm.getCustomFieldObjects(issue).find {it.name == 'IssueNumber'};
setCustomFieldValue(MeD, totalIssues);
} catch (SearchException e) {
e.printStackTrace();
}
}
I'm not getting excepted result with this script and I'm very much new to groovy world, so can't figure out the issue. Can anybody from here help me to sort it out.. please?
Many thanks in advance.
try some thing like this
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.bc.issue.search.SearchService; import com.atlassian.jira.bc.issue.search.SearchService.ParseResult; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.security.JiraAuthenticationContext; import com.atlassian.jira.issue.search.SearchException; import com.atlassian.jira.issue.search.SearchResults; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.query.Query; import com.atlassian.jira.jql.builder.JqlClauseBuilder; import com.atlassian.jira.jql.builder.JqlQueryBuilder; import com.atlassian.jira.issue.search.SearchProvider; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.customfields.option.Option; JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); SearchService searchService = ComponentAccessor.getComponentOfType(SearchService .class); JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder(); CustomField cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom field name1"); Option cf1Value=null; if(cf1 !=null) cf1Value=(Option)issue.getCustomFieldValue(cf1); Option cf2Value=null CustomField cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom field name2"); if(cf2 !=null) cf2Value=(Option)issue.getCustomFieldValue(cf2); int totalIssues=0; if(cf1Value != null && cf2Value != null){ Query query=builder.project().eq("demo").and().customField(cf1.getIdAsLong()).Eq(cf1Value.getValue()).and().customField(cf2.getIdAsLong()).Eq(cf2Value.getValue()).buildQuery(); SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class); SearchResults searchResults = searchProvider.search(query, authenticationContext.getLoggedInUser(), PagerFilter.getUnlimitedFilter()); List<Issue> searchIssues = searchResults.getIssues(); totalIssues = searchIssues.size(); } IssueManager issueManager = ComponentAccessor.getIssueManager(); CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager(); def MeD =cfm.getCustomFieldObjectByName("IssueNumber"); issue.setCustomFieldValue(MeD, Integer.toString(totalIssues)); issueManager.updateIssue(authenticationContext.getLoggedInUser(),issue,EventDispatchOption.DO_NOT_DISPATCH,true);
use following import
import com.atlassian.jira.issue.search.SearchProvider;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting error,
2013-11-05 13:04:19,338 http-bio-8443-exec-24 ERROR admin 784x18837x1 dzusjs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script36.groovy: 19: unable to resolve class SearchProvider
@ line 19, column 16.
SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
error,
2013-11-05 13:59:51,183 http-bio-8443-exec-8 ERROR admin 839x18859x1 dzusjs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.customField() is applicable for argument types: (java.lang.String) values: [Application]
Possible solutions: customField(java.lang.Long)
2013-11-05 13:59:51,184 http-bio-8443-exec-8 ERROR admin 839x18859x1 dzusjs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultJqlClauseBuilder.customField() is applicable for argument types: (java.lang.String) values: [Application]
Possible solutions: customField(java.lang.Long)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i have updated my answer!!
for your reference
https://answers.atlassian.com/questions/199278/find-collection-of-issues-by-customfieldvalue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or is it possible to fetch the custom field value from same issue (from create screen) to the groovy script jql query.
example,
jql query - project = demo and customfeild1 = "customfield1 value from same issue" and customfield2 = "customfield2 value from same issue"
Hope its clear.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Error,
2013-11-06 06:50:06,706 http-bio-8443-exec-16 ERROR admin 410x19227x1 dzusjs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultConditionBuilder.Eq() is applicable for argument types: (java.lang.String) values: [CRM WORKBENCH]
Possible solutions: eq(java.lang.String), eq(), eq(com.atlassian.query.operand.Operand), eq(java.lang.Long), eq(java.util.Date), gt(java.lang.String)
2013-11-06 06:50:06,707 http-bio-8443-exec-16 ERROR admin 410x19227x1 dzusjs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.jql.builder.DefaultConditionBuilder.Eq() is applicable for argument types: (java.lang.String) values: [CRM WORKBENCH]
Here, "CRM WORKBENCH" is one of the values in customfield1. Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you do the query on issue navigator and share that query here so i will give you the equevalent query in jira api
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm talking about, is it possible to have a dyanmic jql query in groovy script. Means, whenever I"m creating an issue, selecting two mandatory custom field (select list field) values like, customfeild1 = "first value" & customfield2 = "1st value".
So, is it possible to add these custom field values over there in groovy script jql search? ie here, jql becomes
project= "demo" and customfield1 = "first value" and customfield2 = "1st value".
If issue creating with some other values in custom field like, customfield1 = "test value" and customfield2 = "first value", so then jql becomes,
project = "demo" and customfield1 = "test value" and customfield2 = "first value"
Is this possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes we can do this, i have updated the answer, try with that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting error,
2013-11-06 08:03:37,576 http-bio-8443-exec-15 ERROR admin 483x19435x1 1fbhjrs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
2013-11-06 08:03:37,576 http-bio-8443-exec-15 ERROR admin 483x19435x1 1fbhjrs 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
Do you need full error log?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Eq() should be lower-case.
Log the value of the two custom fields and their values and check they are not null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just made "eq()" and here cuustom fields are mandaory field but still getting error,
2013-11-06 08:17:58,850 http-bio-8443-exec-1 ERROR admin 497x19533x1 1g32ekn 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
2013-11-06 08:17:58,850 http-bio-8443-exec-1 ERROR admin 497x19533x1 1g32ekn 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:35)
at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:846)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:490)
at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:428)
at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:184)
at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:149) <+2>
at java.lang.reflect.Method.invoke(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
replace query with following code
Query query=builder.project().eq("demo").and().customField(cf1.getIdAsLong()).Eq(cfValues['custom field name1'].value).and().customField(cf2.getIdAsLong()).Eq(cfValues['custom field name2'].value).buildQuery();
is select list fields are not mandatory?
and make sure that you have changed the custom field names
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After using new query, getting error like,
2013-11-06 08:26:30,434 http-bio-8443-exec-10 ERROR admin 506x19553x1 1g32ekn 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: cfValues for class: Script44
2013-11-06 08:26:30,434 http-bio-8443-exec-10 ERROR admin 506x19553x1 1g32ekn 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: cfValues for class: Script44
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i have updated my answer again, all my code is based on java syntax and i don't have knowldge on groovy syntax
i think some one who have good knowldge on groovy(@Jamie) can resolve this fast
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's not a syntax issue, but I will happily write it for him if he pays me.
cfValues is not available in all contexts, he should use customfieldmanager etc to get the cf value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any suggestions on below error,
2013-11-06 09:19:06,710 http-bio-8443-exec-13 ERROR admin 559x19803x1 1a6f5bb 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalArgumentException: Source GenericValue can not be null.
2013-11-06 09:19:06,711 http-bio-8443-exec-13 ERROR admin 559x19803x1 1a6f5bb 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.IllegalArgumentException: Source GenericValue can not be null.
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just moved the workflow script runner post function to issue's first status and getting below error,
2013-11-06 10:02:55,995 http-bio-8443-exec-1 ERROR admin 602x20066x1 j43i17 147.60.54.185 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
2013-11-06 10:02:55,995 http-bio-8443-exec-1 ERROR admin 602x20066x1 j43i17 147.60.54.185 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
Previusoly tried the same from create issue transistion and getting specific "Generic value can not be null" error.
Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which line it throwing null pointer exception?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Make it the last post-function in the list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Caused by: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
... 192 more
Caused by: java.lang.NullPointerException
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:948)
at com.atlassian.jira.issue.MutableIssue$setCustomFieldValue.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at com.atlassian.jira.issue.MutableIssue$setCustomFieldValue.call(Unknown Source)
at Script48.run(Script48.groovy:42)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
... 193 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I made to last in the list but still getting same error.
which line it throwing null pointer exception? -> How I can find this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
at Script48.run(Script48.groovy:42)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any help Rambanam??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry Sanu!! i tried my best to help you!
i can't help more than this because i never worked on Groovy and script runner plugin :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sanu, you need to put a bit more effort into this. To log the output use
log.warn(variable)
You will find the output in atlassian-jira.log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam & Jamie,
Thanks a lot for your valuable help. Finally it got worked :) :)
Could you please suggest additionaly how I can add "issue created within this week" parameter to jql query?
Current one is - Query query=builder.project().eq("DEMO").and().customField(cf1.getIdAsLong()).eq(cf1Value.getValue()).and().customField(cf2.getIdAsLong()).eq(cf2Value.getValue()).buildQuery();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
createdAfter("-7d") is working but need something like created >= -1w. Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
createdAfter("-1w") is working, but want to find specifically from start of this week like, created >= startOfWeek(). Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam,
Any suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what is the code of at Script48.run(Script48.groovy:42)?
what is the jira version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService .class);
JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder();
CustomField cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Application");
Option cf1Value=null;
if(cf1 !=null)
cf1Value=(Option)issue.getCustomFieldValue(cf1);
Option cf2Value=null
CustomField cf2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Issue category");
if(cf2 !=null)
cf2Value=(Option)issue.getCustomFieldValue(cf2);
int totalIssues=0;
if(cf1Value != null && cf2Value != null){
Query query=builder.project().eq("FX QA Support").and().customField(cf1.getIdAsLong()).eq(cf1Value.getValue()).and().customField(cf2.getIdAsLong()).eq(cf2Value.getValue()).buildQuery();
SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
SearchResults searchResults = searchProvider.search(query, authenticationContext.getLoggedInUser(), PagerFilter.getUnlimitedFilter());
List<Issue> searchIssues = searchResults.getIssues();
totalIssues = searchIssues.size();
}
IssueManager issueManager = ComponentAccessor.getIssueManager();
CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager();
def MeD =cfm.getCustomFieldObjectByName("Bronzeissue");
issue.setCustomFieldValue(MeD, Integer.toString(totalIssues));
issueManager.updateIssue(authenticationContext.getLoggedInUser(),issue,EventDispatchOption.DO_NOT_DISPATCH,true);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
are you looking for 42nd line? then,
issue.setCustomFieldValue(MeD, Integer.toString(totalIssues));
Jira - 6.0.5
Can you please guide what does this "Script48.run(Script48.groovy:42)" mean? which line I need to check for this??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you replace last line with following code
issueManager.updateIssue(authenticationContext.getUser().getDirectoryUser(),issue,EventDispatchOption.DO_NOT_DISPATCH,true);
and also give prints and check
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Can you please guide what does this "Script48.run(Script48.groovy:42)" mean
It means see line 42 of your script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam,
Still getting same "NullPointerException" error.
2013-11-07 06:43:22,687 http-bio-8443-exec-10 ERROR admin 403x20583x1 1ay98xf 147.60.54.185 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
It showing as lline 42 in script having the issue,
at Script52.run(Script52.groovy:42)
ie - issue.setCustomFieldValue(MeD, Integer.toString(totalIssues));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
print all the values like current issue, custom field names and it's value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry.. how I can do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is it - document.writeln("Last Modified: " + cf1Value)??
so it will be,
if(cf1 !=null)
cf1Value=(Option)issue.getCustomFieldValue(cf1);
document.writeln("Last Modified: " + cf1Value)
Also do I need to add any additonal import lines to this script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try witht his script
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.bc.issue.search.SearchService; import com.atlassian.jira.bc.issue.search.SearchService.ParseResult; import com.atlassian.jira.event.type.EventDispatchOption; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.security.JiraAuthenticationContext; import com.atlassian.jira.issue.search.SearchException; import com.atlassian.jira.issue.search.SearchResults; import com.atlassian.jira.issue.CustomFieldManager; String jqlSearch = "filter= \"" + filterName + "\""; JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); SearchService searchService = ComponentAccessor.getComponentOfType(SearchService .class); ParseResult parseResult = searchService.parseQuery(authenticationContext.getLoggedInUser(), jqlSearch); int totalIssues = 0; if (parseResult.isValid()) { SearchResults results = searchService.search(authenticationContext.getLoggedInUser(), parseResult.getQuery(), PagerFilter .getUnlimitedFilter()); final List issues = results.getIssues(); totalIssues = issues.size(); //add code here to update custom field IssueManager issueManager = ComponentAccessor.getIssueManager(); CustomFieldManager cfm=ComponentAccessor.getCustomFieldManager(); def MeD =cfm.getCustomFieldObjectByName("IssueNumber"); issue.setCustomFieldValue(MeD, totalIssues); issueManager.updateIssue(authenticationContext.getLoggedInUser(),issue,EventDispatchOption.DO_NOT_DISPATCH,true); }
don't forget to add error messages here if you got any
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Getting error like,
2013-11-05 08:01:03,347 http-bio-8443-exec-20 ERROR admin 481x17117x1 e5wfg3 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: demo for class: Script22
2013-11-05 08:01:03,348 http-bio-8443-exec-20 ERROR admin 481x17117x1 e5wfg3 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: demo for class: Script22
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the filter name should be something like this
String jqlSearch = "filter= \"demo\"";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now getting,
2013-11-05 08:20:10,996 http-bio-8443-exec-22 ERROR admin 500x17670x1 fazx5 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: PagerFilter for class: Script23
2013-11-05 08:20:10,996 http-bio-8443-exec-22 ERROR admin 500x17670x1 fazx5 147.60.54.185 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: PagerFilter for class: Script23
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
add the following import
import com.atlassian.jira.web.bean.PagerFilter;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry.. now getting,
2013-11-05 08:43:16,565 http-bio-8443-exec-22 ERROR admin 523x17789x1 4jb22a 147.60.54.185 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
2013-11-05 08:43:16,565 http-bio-8443-exec-22 ERROR admin 523x17789x1 4jb22a 147.60.54.185 /secure/CreateIssueDetails.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
at javax.script.AbstractScriptEngine.eval(Unknown Source)
My custom field (IssuNumber) is a free text field, is that causing the issue here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, you are correct!
you need to pass string as a paramenter to following method
issue.setCustomFieldValue(MeD, totalIssues);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you don't mind, how it will be?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can try with
Integer.toString(totalIssues) or String.valueOf(totalIssues)
finally it should be like this
issue.setCustomFieldValue(MeD, Integer.toString(totalIssues));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Many thanks Rambanam for the valuable help.
Cheers!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it worked!!
i hope you can close following issue by accepting my as answer as correct :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rambanam,
Is it possible to add custom jql search instead of saved issue filter in above groovy script itself?, If so, what are the changes needs to be performed?
jql example - project = demo and customfield = "ABC" and customfeild2 = "123"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes we can we can add custom jql search, check my another answer!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you remove the try/catch... that is sending the exception to stdout, perhaps you are looking at the wrong log file.
Where is setCustomFieldValue(..) defined?
Where are you specifying on which issue to update the CF?
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.