Hi.
I have tried to use the behaviours plugin with JIRA 4.4 but for some reason it looks like the values are not parced correct.
here is the expample:
import
org.ofbiz.core.entity.GenericValue
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)
After banging my head for a day and a bit, this C/Perl guy believes I have found the problem. In the catalina.out log file, I kept seeing the error:
Cannot cast object '10600' with class 'java.lang.String' to class 'java.lang.Long'
As part of the for loop, the componentId cannot be cast as Long, it is a String so change it from
for (Long componentId : componentIds) {
to
for (String componentId : componentIds) {
and it all works now.
Next, problem to tackle only disable inline editting of this SubComponent field and not all the fields!
Same issue here as well. In the logs I get
2013-04-18 11:58:54,697 http-bio-8080-exec-10 ERROR user 718x10939x1 y738lx 10.9.39.188 /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 'null' with class 'com.atlassian.jira.util.json.JSONObject$Null' to class '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.
Hi,
I have the same problem with the same example: it shows either all values no matter what is the component setting.Can anybody help me?. I'm working on Jira 5.2.7.
Thanks in advanced.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hope someone has an answer because I'm trying to do the same thing in Jira 5.2.2.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
i try to get the example running, too. But i also get an error using the following validator script (based on your example):
import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.ComponentManager ComponentManager componentManager = ComponentManager.getInstance() 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 ([10002:"Lemons", 10003:"Oranges"]) break case "Component 2" : fieldOptions.putAll ([10004:"Spinach", 10005:"Celery"]) break } } formSubcomponent.setFieldOptions (fieldOptions)
I always get the following error:
127.0.0.1 /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 '10002' with class 'java.lang.String' to class 'java.lang.Long'
Using JIRA 4.4.5, Behaviour plugin 0.5.0, Script runner 2.0.6
Regards, Wolfgang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cannot cast object '10002' with class 'java.lang.String' to class 'java.lang.Long'
Not sure which bit of your code is failing but it needs casting to a long, eg
thing as Long
or "new Long (thing)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
i'm trying to get the example working for me to (in a new test instance).
Test project is created with the Components "Component 1" and "Component 2", mulitselect field "Subcomponents" is created with the example values.
I use the following behavior validation script (based on your example):
import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.ComponentManager ComponentManager componentManager = ComponentManager.getInstance() 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 ([10002:"Lemons", 10003:"Oranges"]) break case "Component 2" : fieldOptions.putAll ([10004:"Spinach", 10005:"Celery"]) break } } formSubcomponent.setFieldOptions (fieldOptions)
But when i try to edit an issue i get thw following errors in log:
127.0.0.1 /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 '10002' with class 'java.lang.String' to class 'java.lang.Long'
Regards,
Wolfgang
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think we are having the same conversation here https://studio.plugins.atlassian.com/wiki/display/JBHV/Miscellaneous+Behaviours+Examples?focusedCommentId=67797592#comment-67797592 right?
There are two problems. That is only sample code, so unless you have components called Component 1 or Component 2 then neither of the two cases will match.
However, in that case, you should see no options, not all options.
You have no definition for componentManager, you need to add near the top:
import com.atlassian.jira.ComponentManager
Therefore I need to change the code to:
fieldOptions.putAll ([
"10030"
:
"Lemons"
,
"10031"
:
"Oranges"
])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Jamie.
Thanks for the support.
Yes, this is the same conversation.
It seems like I need the log files, so I made the same set up on a sandbox JIRA.
I enabled the log file.
After enabling the logging, in the atlassian-jira.log I see only:
{code}2012-02-20 00:26:41,737 http-8443-7 DEBUG tnikolov 26x17135x1 z4e44 192.168.164.1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [:]
{code}
I have Component 1 and Component 2 for this project.
I have also added a fifth subcomponent- Onions in the list.
I do not get the error message for wrong ID's (or I do not know where to look for it)
If I choose either Component 1 or Component 2 or some other component from the list (e.g Component 3, for wich there is no rule in the code), I see all the five options in the subcomponent field.
Is it possible for some reason the code not to be able to recognize the parced value of the component and to put all values because of this ?
Thnak you and excuse for doubling the issue.
I am really keen on using behaviours.
Cheers, Tihomir.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you definitely mapped this behaviour to this project, and that there are no other behaviours also mapped (just because it will confuse debugging)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Jamie.
I Confirm that the behaviour is attached to the project I am testing with.
Cheers, Tihomir.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using JIRA Behaviour Plugin to populate Multi-Select customfield options based on a custom field select list option as indicated in https://jamieechlin.atlassian.net/wiki/display/JBHV/Miscellaneous+Behaviours+Examples
JIRA version : 5.2.7 and
Behaviour Plugin - 0.5.3
But I keep hitting this and The script populates the full list of options. I see no error in the logs except this.
/rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [:]
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.