It's not the same without you
Join the community to find out what other Atlassian users are discussing, debating and creating.
I am looking to populate a Sub Components Select List Custom Field based on what the user selects in the Components field. Based on the examples shown with the Behaviors Plugin I wasn't sure if it could do this or not and I'm also new to Jira.
So basically if the user selects Server for example I'd like to set the value of Sub Components to a list of values like 'GUI','Networking','Admin', etc.
From the examples I saw I can set a particular form value but I wasn't sure how to supply a list of values.
Thanks,
J
Sure. I found it on the Behaviors plugin site. It's one of the Child links on the main documentation page. Here's the link to the page with the info on it:
https://studio.plugins.atlassian.com/wiki/display/JBHV/Miscellaneous+Behaviours+Examples
Then scroll down a bit to the Add or Remove options to single or multi-select fields.
J
While I did find some info in the Script Sample file and I can get the Sub Components list to populate I cannot get it to accept a selection once it's been populated. Instead it throws an error about the only values available are blank and -1.
The initial Select List has no values as I am trying to set them dynmically based on the Component selection. Has anyone been able to do this? I am using the code from the Script sample so perhaps it doesn't really work, this particular funciton is not documented at all.
Thanks,
J
For Behaviours you have to enter them via the Behaviours editor which you get to from the Behaviours menu item in the Add-ons section of the Admin pages.
Take a look at their online help as it's pretty good:
https://jamieechlin.atlassian.net/wiki/display/JBHV/JIRA+Behaviours+Plugin
If you're looking for Validators then you don't use Behaviours for that, instead you can use the other add-on, Script-Runner. Same developer. Here's the online help for that one so you can see what you can do with that:
https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner
Good Luck.
J
public class ScriptSample extends FieldBehaviours { Category log = Category.getInstance(ScriptSample.class) ComponentManager componentManager = ComponentManager.getInstance() public void setOFSubComponentOptions() { FormField formComponent = getFieldById(fieldChanged) FormField formSubcomponent = getFieldByName("Sub-Components") def AdminSubComponents = ["12357":"Users","12356":"Groups"] def DatabaseSC = ["19922":"Migration","19923":"Scripts"] 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") componentIds.each {componentId -> try { Long.parseLong(componentId as String) } catch (NumberFormatException e) { log.error("Could not get component Id as Long") return } GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId)) log.debug "name: \"" + component?.get("name") + "\"" switch (component?.get("name")) { case "Admin": fieldOptions.putAll(AdminSubComponents) break case "Database": fieldOptions.putAll(DatabaseSC) break default: fieldOptions.put("-1", "None") break } }
formSubcomponent.setFieldOptions(fieldOptions) }}
See the instructions for the plugin. When you create the Behavior you can point it to a file containing the script.
If you're using Jira 6.3 the plugin is now part of the Script Runner, once you install that you'll have a Behaviors area in the Add-ons section of Admin.
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.
Read moreAtlas Camp is our developer event which will take place in Barcelona, Spain from the 6th -7th of September . This is a great opportunity to meet other developers and get n...
Connect with like-minded Atlassian users at free events near you!
Find a groupConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.
Start an AUGYou're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.