Behaviours Plugin - How to change the options listed in a Custom Field based on the value selected in the Components Field

Harish August 22, 2012

Hi Team,

We have Jira 4.4.5 and have installed the Behaviours Plugin Version 0.4.9.

We have a requirment to have a dependency between the System Field 'Components' and the custom Field ' SubComponents'.

SubComponents is a Single select list. The options displayed in the select list should depend on the value selected for the 'Component' field.

How can this be achieved using the Behaviours plugin. Please let me know how to write a server-side script if any required to achieve this feature.

Thanks in advance,

Harish.

6 answers

1 vote
Radha Khullar November 14, 2018

Thanks it was a great help.

I was able to write behaviour plugin based on the above shared code.

Below is the working code for me in case someone needs.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def selectList1 = getFieldById(fieldChanged)
def selectList2 = getFieldByName("Sub-component")

def selectList1Val = selectList1.getValue()
Map fieldOptions = [:] 
fieldOptions.put ("-1", "None") 

selectList1Val.each{
def selectListname = it.getAt("name")

switch (selectListname){
case "Comp 1" :fieldOptions.putAll (["22601":"Sub1", "22602":"Sub2", "22603":"Sample Sub 3"])
break 
case "Comp 2" :fieldOptions.putAll (["22604":"Sample Sub 1", "22605":"Sub 2 sample"]) 
break 
}

}
selectList2.setFieldOptions (fieldOptions)

 

The numbers 22601 through 22605 are the option ids that can be retrieved by hover on Edit link of option value under "Edit Options for Custom Field"

0 votes
PetraPensky December 18, 2014

Hello everyone.

I have the same problem.
Debug "1" is shown. Debug "2" not... Can anyone please help me.

Thanks in advance.
  Petra

import org.ofbiz.core.entity.GenericValue
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils
FormField formComponent = getFieldById(fieldChanged)
FormField formSubcomponent = getFieldByName ("Subcomponent")

Object componentFormValue = formComponent.getFormValue()
List componentIds = []

if (componentFormValue instanceof List) {
componentIds.addAll(componentFormValue as List)
}
else {
// could be an empty string if all components are deselected
if (componentFormValue) {
componentIds.add(componentFormValue)
}
}

Map fieldOptions = [:]
fieldOptions.put ("-1", "None")
log.error ("1") 
for (Long componentId : componentIds) {
try {
log.error ("2") 
log.error (componentId)
log.error ("3") 
Long.parseLong(componentId)
log.error ("4") 
} catch (NumberFormatException e) {
log.error ("Could not get component Id as Long")
return
}

GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))

switch (component?.get("name")) {
case "Software" :
fieldOptions.put ("10680", "MS Office")
fieldOptions.put ("10681", "Snapware")
fieldOptions.put ("10682", "Sonstige Software")
break
}
}
formSubcomponent.setFieldOptions (fieldOptions)
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 18, 2014

Not sure what you mean by "debug 2". Are you saying it doesn't print "2" from "log.error("2")" ?

PetraPensky December 18, 2014

Yeah. It doesn't print the "2".

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 18, 2014

That could mean componentIds is empty? If you don't get that there should be some other messages, maybe an error stack trace?

PetraPensky December 18, 2014

I don't think so, because I have chosen a component. When I remove the component, the "1" is being printed and no error appears in the log. {code} 2014-12-18 17:45:14,681 http-bio-8080-exec-5597 ERROR petrapensky 1065x739142x1 1gjulsq 89.21.6.7 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with method run in class org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '12819' with class 'java.lang.String' to class 'java.lang.Long' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:143) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599) at Script1.run(Script1.groovy:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at sun.reflect.GeneratedMethodAccessor5196.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120) at com.onresolve.jira.groovy.BehaviourManagerImpl$_runValidator_closure5.doCall(BehaviourManagerImpl.groovy:170) at sun.reflect.GeneratedMethodAccessor5243.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) at groovy.lang.Closure.call(Closure.java:411) at groovy.lang.Closure.call(Closure.java:427) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1325) at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1297) at org.codehaus.groovy.runtime.dgm$148.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at com.onresolve.jira.groovy.BehaviourManagerImpl.runValidator(BehaviourManagerImpl.groovy:123) at sun.reflect.GeneratedMethodAccessor1704.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:231) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145) at com.onresolve.jira.groovy.BehaviourManagerImpl.runValidator(BehaviourManagerImpl.groovy:88) at com.onresolve.jira.behaviour.restservice.MessageResource.runValidator(MessageResource.java:75) at sun.reflect.GeneratedMethodAccessor1703.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:178) at com.sun.jersey.spi.container.servlet.ServletContainer.doFilter(ServletContainer.java:795) at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:73) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilterInternal(RestServletUtilsUpdaterFilter.java:26) at com.atlassian.plugins.rest.module.servlet.RestServletUtilsUpdaterFilter.doFilter(RestServletUtilsUpdaterFilter.java:40) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.applinks.core.rest.context.ContextFilter.doFilter(ContextFilter.java:25) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(ServingRequestsFilter.java:37) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.plugins.cors.CorsFilter.doFilter(CorsFilter.java:65) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsDispatcherFilter.doFilter(PrettyUrlsDispatcherFilter.java:60) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsSiteMeshFilter.doFilter(PrettyUrlsSiteMeshFilter.java:92) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsMatcherFilter.doFilter(PrettyUrlsMatcherFilter.java:56) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.labs.botkiller.BotKillerFilter.doFilter(BotKillerFilter.java:36) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.web.filters.accesslog.AccessLogFilter.executeRequest(AccessLogFilter.java:103) at com.atlassian.jira.web.filters.accesslog.AccessLogFilter.doFilter(AccessLogFilter.java:87) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.security.xsrf.XsrfTokenAdditionRequestFilter.doFilter(XsrfTokenAdditionRequestFilter.java:54) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.web.filters.steps.ChainedFilterStepRunner.doFilter(ChainedFilterStepRunner.java:87) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.seraph.filter.SecurityFilter.doFilter(SecurityFilter.java:234) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.security.auth.trustedapps.filter.TrustedApplicationsFilter.doFilter(TrustedApplicationsFilter.java:100) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.seraph.filter.BaseLoginFilter.doFilter(BaseLoginFilter.java:169) at com.atlassian.jira.web.filters.JiraLoginFilter.doFilter(JiraLoginFilter.java:70) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.oauth.serviceprovider.internal.servlet.OAuthFilter.doFilter(OAuthFilter.java:61) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:40) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.johnson.filters.AbstractJohnsonFilter.doFilter(AbstractJohnsonFilter.java:71) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176) at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145) at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92) at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.gzipfilter.GzipFilter.doFilterInternal(GzipFilter.java:80) at com.atlassian.gzipfilter.GzipFilter.doFilter(GzipFilter.java:51) at com.atlassian.jira.web.filters.gzip.JiraGzipFilter.doFilter(JiraGzipFilter.java:55) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:46) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter$1.doFilter(DelegatingPluginFilter.java:66) at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61) at com.atlassian.plugin.servlet.filter.DelegatingPluginFilter.doFilter(DelegatingPluginFilter.java:74) at com.atlassian.plugin.servlet.filter.IteratingFilterChain.doFilter(IteratingFilterChain.java:42) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:77) at com.atlassian.plugin.servlet.filter.ServletFilterModuleContainerFilter.doFilter(ServletFilterModuleContainerFilter.java:63) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.web.filters.steps.ChainedFilterStepRunner.doFilter(ChainedFilterStepRunner.java:87) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.core.filters.cache.AbstractCachingFilter.doFilter(AbstractCachingFilter.java:33) at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.core.filters.encoding.AbstractEncodingFilter.doFilter(AbstractEncodingFilter.java:41) at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31) at com.atlassian.jira.web.filters.PathMatchingEncodingFilter.doFilter(PathMatchingEncodingFilter.java:45) at com.atlassian.core.filters.AbstractHttpFilter.doFilter(AbstractHttpFilter.java:31) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.startup.JiraStartupChecklistFilter.doFilter(JiraStartupChecklistFilter.java:78) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.web.filters.MultipartBoundaryCheckFilter.doFilter(MultipartBoundaryCheckFilter.java:41) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at com.atlassian.jira.web.filters.steps.ChainedFilterStepRunner.doFilter(ChainedFilterStepRunner.java:87) at com.atlassian.jira.web.filters.JiraFirstFilter.doFilter(JiraFirstFilter.java:57) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) {code}

PetraPensky December 29, 2014

Hi Jamie, thanks for your answers. I changed componentId to String and it works so far... But then I got trouble with GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId)) due to API changes. componentManager is deprecated and everythings seems to be different now. I just switch the component by ID, because the solution is only for one project and I will not get any trouble... Regards, Petra

0 votes
John Woolley April 25, 2013

Same type of errors in my log as well!

Marco Colageo June 12, 2013

Same problem too.

By commenting the codelines below I've got the subComponent field set to None.

for (Long componentId : componentIds) {
        /*try {
            Long.parseLong(componentId)
        } catch (NumberFormatException e) {
            log.error ("Could not get component Id as Long")
            return
        }*/
 
       .......

So I assume that the try/catch gives an exception. Is there a way to rewrite this step to try something different?

Cheers

Marco

0 votes
Bryan Karsh
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.
April 25, 2013

Hi,

I'm also getting similar problem (script pasted in seems to execute fine, but despite choosing component, subcomponent is not updated from "None") -- note, field for subcomponent is a multiselect list, populated with values you mentioned. custom field is associated with project, and shows all values when behavior is not turned on. When behavior is turned on, the 'None' value displays.

Any tips appreciated. I am running Jira 5.2.6, and most recent behavior plugin.

import org.ofbiz.core.entity.GenericValue
    import com.atlassian.core.ofbiz.util.OFBizPropertyUtils
    
    FormField formComponent = getFieldById(fieldChanged)
    FormField formSubcomponent = getFieldByName ("Subcomponent")
 
    Object componentFormValue = formComponent.getFormValue()
    List componentIds = []
 
    if (componentFormValue instanceof List) {
        componentIds.addAll(componentFormValue as List)
    }
    else {
        // could be an empty string if all components are deselected
        if (componentFormValue) {
            componentIds.add(componentFormValue)
        }
    }
 
    Map fieldOptions = [:]
    fieldOptions.put ("-1", "None")
 
    for (Long componentId : componentIds) {
        try {
            Long.parseLong(componentId)
        } catch (NumberFormatException e) {
            log.error ("Could not get component Id as Long")
            return
        }
 
        GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))
 
        switch (component?.get("name")) {
            case "Component 1" :
                fieldOptions.putAll (["Lemons":"Lemons", "Oranges":"Oranges"])
                break
 
            case "Component 2" :
                fieldOptions.putAll (["Spinach":"Spinach", "Celery":"Celery"])
                break
 
        }
    }
    formSubcomponent.setFieldOptions (fieldOptions)

Bryan Karsh
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.
April 25, 2013

Some log info:

2013-04-25 12:40:07,921 http-bio-8080-exec-8277 DEBUG XXXXX 760x307408x2 iwlrna XXXXXXXXXXXXXXXXXXXXXXXXXX

/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.PostFunction] debug statements

2013-04-25 12:40:07,922 http-bio-8080-exec-8277 ERROR XXXXXX 760x307408x2 iwlrna XXXXXXXXXXXXXXXXXXXXXX/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Something went wrong with method run in class

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '11771' with class 'java.lang.String' to class 'java.lang.Long'

at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:143)

at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)

at Script1.run(Script1.groovy:30)

0 votes
John Woolley April 17, 2013

Same problem here that non of my subcomponents are changed when I choose the initial component. Did you eventually solve your issue?

0 votes
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.
August 22, 2012
Harish August 23, 2012

Hi Jamie,

Thanks for the reponse.

I have written the script for my components and subcomponents refering the example given in the link sent by you.

I have pasted the script in the 'Add server side script' option in the Behaviour plugin.

I get a compilation error as below :

"Compilation failure: startup failed: Script1.groovy: 23: unable to resolve class GenericValue @ line 23, column 16. GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId)) ^ 1 error "

The script i have written is as below :

public void setSubComponentOptions ()
{
FormField formComponent = getFieldById(fieldChanged)
FormField formSubcomponent = getFieldById("customfield_10502")
Object componentFormValue = formComponent.getFormValue()
List componentIds = []
if (componentFormValue instanceof List)
{ componentIds.addAll(componentFormValue as List)}
else {
if (componentFormValue) { componentIds.add(componentFormValue) }
}
Map fieldOptions = [:]
fieldOptions.put ("-1", "None")
for (Long componentId : componentIds)
{
try { Long.parseLong(componentId)}
catch (NumberFormatException e)
{ log.error ("Could not get component Id as Long")
return
}
GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))
switch (component?.get("name"))
{
case "Comp 1" :fieldOptions.putAll (["Sub1":"Sub1", "Sub2":"Sub2", "Sample Sub 3":"Sample Sub 3"])
break
case "Comp 2" :fieldOptions.putAll (["Sample Sub 1":"Sample Sub 1", "Sub 2 sample":"Sub 2 sample"])
break
case "Comp 3" :fieldOptions.putAll (["N/A":"N/A"])
break

}
}
formSubcomponent.setFieldOptions (fieldOptions)

}

Please let me know if i am wrong in the script.

Also i dint not understand where the validator code is to be placed. Is it the server side script option only? i dint find the place to paste any code in the validator s option for a workflow transition.

Thanks,

Harish.

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.
August 23, 2012

The example was for having a method in a file, if you're pasting it in then remove the "public void setSubComponentOptions ()" and closing }. Also add the imports:

import org.ofbiz.core.entity.GenericValue
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils


Harish August 23, 2012

Hi Jamie,

I have removed the "Public void ..." as it is not a method.

Pasted the import statements just above the first line of the code , the script looks as below :

import org.ofbiz.core.entity.GenericValue
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils
FormField formComponent = getFieldByName("components")
FormField formSubcomponent = getFieldById("customfield_10502")
Object componentFormValue = formComponent.getValue()
List componentIds = []
if (componentFormValue instanceof List)
{ componentIds.addAll(componentFormValue as List)}
else {
if (componentFormValue) { componentIds.add(componentFormValue) }
}
Map fieldOptions = [:]
fieldOptions.put ("-1", "None")
for (Long componentId : componentIds)
{
try { Long.parseLong(componentId)}
catch (NumberFormatException e)
{ log.error ("Could not get component Id as Long")
return
}
GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))
switch (component?.get("name"))
{
case "Comp 1" :fieldOptions.putAll (["Sub1":"Sub1", "Sub2":"Sub2", "Sample Sub 3":"Sample Sub 3"])
break
case "Comp 2" :fieldOptions.putAll (["Sample Sub 1":"Sample Sub 1", "Sub 2 sample":"Sub 2 sample"])
break
case "Comp 3" :fieldOptions.putAll (["N/A":"N/A"])
break

}
}
formSubcomponent.setFieldOptions (fieldOptions)

There is no effect taking place with this script.

The options which were defined in the Field configuration for the subcomponent field are all disabled, as the options are dynamically defined in the script.

The Components field is a multi select rendered.

Do i have to enable the Behaviours Plugin through the 'User Installed Plugins' options.

When i click on the Behaviour Plugin under 'User Installed Plugins:" i do not find any Enable/Disable, Uninstall otpions. How can i enable or disable the plugin.

Your response is highly appriciated.

Thanks,

harish.

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.
August 23, 2012

You don't have the plugin installed?

Once installed make sure the behaviour is mapped to your project. Check the docs...

Harish August 23, 2012

Hi Jamie,

I have already installed the Behaviour plugin. Created a behaviour and mapped to a project.

Got a doubt if i need to enable the plugin as the script is not working.

When checked the Behaviour plugin under the 'User Installed Pugins'. the Plugin is available but no options to enable/disable or uninstall.

Pelase refer the snaspshots attached.

Kindly let me know where i am going wrong.

Thanks in advance,

harish.

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.
August 23, 2012

Thanks for the annotated screenshots. The plugin is installed and enabled, otherwise you wouldn't get to the first screen.

The validatator should be on Components, not on Modules. That is, when a component is selected, you want something else to happen. The way you have it, when Modules change, something else will happen.

Harish August 23, 2012

Hi Jamie,

The 'Components' field is re-labled as Modules through out Jira. We have made this customization.

Sorry if forgot to inform you that we re-labled the Components field as Modules.

Thanks,

Harish

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.
August 23, 2012

Add some logging to your script so you can see if it's being invoked.

This is wrong:

FormField formComponent = getFieldByName("components")

The name is not components. Stick with: FormField formComponent = getFieldById(fieldChanged)

If you want to change the example that's fine, but you need to add some logging to log the values of the variables, to check they are what you expect.


Harish August 23, 2012

Hi,

I have made the change to the script . : FormField formComponent = getFieldById(fieldChanged)

But still there is no effect of the Behaviour plugin for the Components ( i.e Modules) field.

When i select or change an option inthe Components field, the Subcomponents list doesnot get updated. It just dispalys 'None'.

Any further suggestions, please help!

Thanks,

Harish.

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.
August 23, 2012

The subcomponent values need to be available... all the plugin can do is remove them from the display. It can't create valid options. So make sure that when the behaviour is not applied, you see all the subcomponent options.

Harish August 26, 2012

Hi Jamie,

I have made the subcomponent options available ( using Edit Options for Custom Field).

Now when the Component field value is changed, the list of SubComponents do not change. The Subcomponnets field lists all the options irrespective of the value selected in the Component field.

Please let me know if i need to add any code for onchange() in the script.

Thanks,

Harish.

Suggest an answer

Log in or Sign up to answer