Using Beahaviours plugin, how can I populate a Select List based on the selection in another?

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.



10 answers

1 accepted

1 vote
Answer accepted

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.


Hi Starbird,

can i get the steps how to do that

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:

Then scroll down a bit to the Add or Remove options to single or multi-select fields.


Found the Scirpt Sample file which has an example to do exactly what I wanted.



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.



How and where did you enter the validator? I have installed the Behaviors plugin already. Thanks.

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:

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:

Good Luck.


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"?

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:
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) {
		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")
		GenericValue component = componentManager.getProjectManager().getComponent(Long.parseLong(componentId))
		log.debug "name: \"" + component?.get("name") + "\""
		switch (component?.get("name")) {
			case "Admin":
			case "Database":
				fieldOptions.put("-1", "None")

Hi Starbird.

This class ScriptSample, where do you use?

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


204 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you