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
After some additional searching online I found a hint that provided my solution. I needed to fully fill in the Select list and then match up the actual ID's. Once I did that it worked like a charm.
Thanks,
J
Hi Starbird,
can i get the steps how to do that
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Starbird.
This class ScriptSample, where do you use?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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) }}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For ours I had to write a script that I put in a file and pointed the
Behaviour at that file on the server.
I'll post a sample of the code here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks so much. So in this case, assuming I have already created a custom field "Subcomponents", what would I enter for the "Class" and "Method"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found the Scirpt Sample file which has an example to do exactly what I wanted.
Thanks,
J
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.