I am using an addon called Label Manager that uses a CustomFieldType class which extends the Label Type "LabelsCFType". I cannot seem to get it to work using a script with an if statement.
If I have it like this it works:
Type = groovy expression
Value = ["my_label_1"]
Like this it doesn't:
if(issue.get("customfield_18275") ==
"ITAM-Request") {return ["Internal_Tools-RequestIT"];}
I do not see any errors or other information when looking at the logs.
Ok, so after all this back and forth, the answer is:
import com.atlassian.jira.issue.label.Label; for (label in issue.get("customfield_18275")) if (label.getLabel() == "ITAM-Request") return [new Label(null, null, "Internal_Tools-RequestIT")] as Set; return null;
I have one follow up question to this. If I wanted to add another line, in addition to what I have already, where it sets this 3rd party label based on what the summary is, how would I do that?
I tried this:
import com.atlassian.jira.issue.label.Label; for (label in issue.get("customfield_18275")) if (label.getLabel() == "ITAM-Request") return [new Label(null, null, "Internal_Tools-RequestIT")] as Set; return null; if (issue.get("summary") == "automated decommission process")return [new Label(null, null, "Security-Decommission")] as Set;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
import com.atlassian.jira.issue.label.Label; def res=[]; for (label in issue.get("customfield_18275")) if (label.getLabel() == "ITAM-Request") res.push(new Label(null, null, "Internal_Tools-RequestIT")); if (issue.get("summary") == "automated decommission process") res.push(new Label(null, null, "Security-Decommission")); return res as Set;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried that, but the summary portion did not work. The original part still works. Nothing in the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Disregard my previous comment. It is working properly. Careless mistake on my end. Thanks for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Cole,
this is because your custom field is an extension of the LabelsCFType and if you look at https://innovalog.atlassian.net/wiki/display/KB/Using+issue.get%28%3Cfield_name%3E%29+in+scripts, you'll notice that issue.get() returns a Set<Label>, not a String. So you'll need to iterate over the set and, for each value, compare its getName() with "ITAM-Request" (using the equals() method, not "==" which returns true only if two Objects are the same):
for (label : issue.get("customfield_18275")) if (label.getName().equals("ITAM-Request")) return "Internal_Tools-RequestIT"; return null;
By the way, why are you returning an array? What kind of calculated field are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply, David. I tried what your code and got an error.
2017-02-10 09:17:13,939 ajp-nio-8009-exec-52 WARN adamsco 557x930187x1 ir9690 10.30.29.82 /secure/WorkflowUIDispatcher.jspa [c.i.j.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: Java-style for-each statement requires a type declaration.; solution: Use the 'in' keyword, as for (x in y) {...} @ line 1, column 12. for (label : issue.get("customfield_18275")) ^ 1 error org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: Java-style for-each statement requires a type declaration.; solution: Use the 'in' keyword, as for (x in y) {...} @ line 1, column 12. for (label : issue.get("customfield_18275")) ^ 1 error at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309) at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119) at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131) at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:142) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:108) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:162) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:912) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:613) at groovy.lang.GroovyShell.parse(GroovyShell.java:625) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:516) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527) at com.innovalog.jmwe.plugins.functions.SetFieldValueFunction.executeFunction(SetFieldValueFunction.java:76) at com.innovalog.jmwe.plugins.functions.AbstractPreserveChangesPostFunction.execute(AbstractPreserveChangesPostFunction.java:124) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446) at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:826) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:786) at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:484) at com.atlassian.jira.web.action.workflow.SimpleWorkflowAction.doExecute(SimpleWorkflowAction.java:28) ... 1 filtered at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63) ... 7 filtered at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ... 55 filtered at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:59) ... 23 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 42 filtered at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70) ... 20 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 21 filtered at com.valiantys.jira.plugins.sql.service.servicedesk.ContextListenerServletFilter.doFilter(ContextListenerServletFilter.java:24) ... 3 filtered at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:169) at com.atlassian.servicedesk.internal.util.scala.ScalaJavaInterOp$1.apply(ScalaJavaInterOp.java:25) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil$.outOfCustomerContext(CustomerContextUtil.scala:48) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil.outOfCustomerContext(CustomerContextUtil.scala) at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.outOfCustomerContext(CustomerContextServiceImpl.java:24) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:164) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:120) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:112) ... 12 filtered at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178) at net.bull.javamelody.PluginMonitoringFilter.doFilter(PluginMonitoringFilter.java:85) at net.bull.javamelody.JiraMonitoringFilter.doFilter(JiraMonitoringFilter.java:105) ... 44 filtered at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
I added an "in" instead of the colon and got a new error:
2017-02-10 09:18:54,731 ajp-nio-8009-exec-66 WARN adamsco 558x930296x1 ir9690 10.30.29.82 /secure/WorkflowUIDispatcher.jspa [c.i.j.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.Label.getName() is applicable for argument types: () values: [] Possible solutions: getLabel(), getAt(java.lang.String), getClass(), getId(), getIssue() groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.Label.getName() is applicable for argument types: () values: [] Possible solutions: getLabel(), getAt(java.lang.String), getClass(), getId(), getIssue() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112) at Script1.run(Script1.groovy:2) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527) at com.innovalog.jmwe.plugins.functions.SetFieldValueFunction.executeFunction(SetFieldValueFunction.java:76) at com.innovalog.jmwe.plugins.functions.AbstractPreserveChangesPostFunction.execute(AbstractPreserveChangesPostFunction.java:124) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446) at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:826) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:786) at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:484) at com.atlassian.jira.web.action.workflow.SimpleWorkflowAction.doExecute(SimpleWorkflowAction.java:28) ... 1 filtered at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63) ... 7 filtered at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ... 55 filtered at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:59) ... 23 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 42 filtered at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70) ... 20 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 21 filtered at com.valiantys.jira.plugins.sql.service.servicedesk.ContextListenerServletFilter.doFilter(ContextListenerServletFilter.java:24) ... 3 filtered at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:169) at com.atlassian.servicedesk.internal.util.scala.ScalaJavaInterOp$1.apply(ScalaJavaInterOp.java:25) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil$.outOfCustomerContext(CustomerContextUtil.scala:48) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil.outOfCustomerContext(CustomerContextUtil.scala) at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.outOfCustomerContext(CustomerContextServiceImpl.java:24) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:164) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:120) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:112) ... 12 filtered at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178) at net.bull.javamelody.PluginMonitoringFilter.doFilter(PluginMonitoringFilter.java:85) at net.bull.javamelody.JiraMonitoringFilter.doFilter(JiraMonitoringFilter.java:105) ... 44 filtered at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
I'm really not trying to return an array. I was just trying out different things to see what worked. Basically I want this 3rd party label field to auto-populate based on what is in the basic label field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry about the errors, I didn't test the script but just wanted to point you in the right direction.
Just like the first error pointed you to the right solution, the second error also points to a solution: use getLabel() instead of getName().
So the Groovy script could look like:
for (label in issue.get("customfield_18275")) if (label.getValue() == "ITAM-Request") return "Internal_Tools-RequestIT"; return null;
Note that I replaced the equals method with == which works for Strings in Groovy (only in Groovy). I got confused before because I thought you were using JIRA Misc Custom Fields, which uses BeanShell (Java) instead of Groovy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I did try to use getLabel() instead of getName(), but I got another error.
com.atlassian.jira.issue.label.Label cannot be cast to java.util.Set
Using your script with the getValue I an error suggesting I use getLabel().
2017-02-10 09:47:06,198 ajp-nio-8009-exec-57 WARN adamsco 587x930979x1 ir9690 10.30.29.82 /secure/WorkflowUIDispatcher.jspa [c.i.j.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.Label.getValue() is applicable for argument types: () values: [] Possible solutions: getIssue(), getClass(), getLabel(), getAt(java.lang.String), getId() groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.label.Label.getValue() is applicable for argument types: () values: [] Possible solutions: getIssue(), getClass(), getLabel(), getAt(java.lang.String), getId()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post the full stack of the "com.atlassian.jira.issue.label.Label cannot be cast to java.util.Set" error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sure.
2017-02-10 09:50:30,988 ajp-nio-8009-exec-52 ERROR adamsco 590x931119x1 ir9690 10.30.29.82 /secure/WorkflowUIDispatcher.jspa [c.a.jira.workflow.OSWorkflowManager] Caught exception while attempting to perform action 31 from workflow 745075 on issue 'ITSD-33835' java.lang.ClassCastException: com.atlassian.jira.issue.label.Label cannot be cast to java.util.Set at rs.codecentric.customfield.LabelITCFType.createValue(LabelITCFType.java:39) at com.atlassian.jira.issue.fields.CustomFieldImpl.createValue(CustomFieldImpl.java:731) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:448) at com.atlassian.jira.issue.fields.CustomFieldImpl.updateValue(CustomFieldImpl.java:434) at com.atlassian.jira.workflow.function.issue.GenerateChangeHistoryFunction.execute(GenerateChangeHistoryFunction.java:54) at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050) at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446) at com.opensymphony.workflow.AbstractWorkflow.doAction(AbstractWorkflow.java:564) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowActionInsideTxn(OSWorkflowManager.java:826) at com.atlassian.jira.workflow.OSWorkflowManager.doWorkflowAction(OSWorkflowManager.java:786) at com.atlassian.jira.bc.issue.DefaultIssueService.transition(DefaultIssueService.java:484) at com.atlassian.jira.web.action.workflow.SimpleWorkflowAction.doExecute(SimpleWorkflowAction.java:28) ... 1 filtered at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:63) ... 7 filtered at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ... 55 filtered at com.atlassian.greenhopper.jira.filters.ClassicBoardRouter.doFilter(ClassicBoardRouter.java:59) ... 23 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 42 filtered at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:70) ... 20 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 3 filtered at org.kantega.atlaskerb.AtlasKerberosFilter.doFilter(AtlasKerberosFilter.java:80) ... 21 filtered at com.valiantys.jira.plugins.sql.service.servicedesk.ContextListenerServletFilter.doFilter(ContextListenerServletFilter.java:24) ... 3 filtered at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:169) at com.atlassian.servicedesk.internal.util.scala.ScalaJavaInterOp$1.apply(ScalaJavaInterOp.java:25) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil$.outOfCustomerContext(CustomerContextUtil.scala:48) at com.atlassian.servicedesk.internal.utils.context.CustomerContextUtil.outOfCustomerContext(CustomerContextUtil.scala) at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.outOfCustomerContext(CustomerContextServiceImpl.java:24) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:164) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:120) at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:112) ... 12 filtered at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:201) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:178) at net.bull.javamelody.PluginMonitoringFilter.doFilter(PluginMonitoringFilter.java:85) at net.bull.javamelody.JiraMonitoringFilter.doFilter(JiraMonitoringFilter.java:105) ... 44 filtered at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This means that this particular custom field type expects a Set<Label> as a value, but it has a buggy implementation of the getValueFromCustomFieldParams method. So, instead of returning a String, you should return a valid Label inside a Set:
for (label in issue.get("customfield_18275")) if (label.getValue() == "ITAM-Request") return ["Internal_Tools-RequestIT"] as Set; return null;
I haven't tested it though (can't without that add-on)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This means that this custom field type expects a Set<Label> as a value but doesn't provide a proper implementation of the getValueFromCustomFieldParams method.
In that case, you need to return a Set<Label> from the Groovy script:
import com.atlassian.jira.issue.label.Label; for (label in issue.get("customfield_18275")) if (label.getValue() == "ITAM-Request") return [new Label(null, null, "Internal_Tools-RequestIT")] as Set; return null;
I haven't tested this script though (can't without the add-on that provides that special Labels type).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That works!
All I had to do was change the getValue() to getLabel() and it set the value on transition.
I appreciate your help David!
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.