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

Jon Starbird
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.
January 7, 2013

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

10 answers

1 accepted

1 vote
Answer accepted
Jon Starbird
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.
January 8, 2013

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

Dinesh Dhinakaran
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2013

Hi Starbird,

can i get the steps how to do that

Jon Starbird
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.
February 3, 2013

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

0 votes
Jon Starbird
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 10, 2014

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.

0 votes
Jorge Fernández August 4, 2014

Hi Starbird.

This class ScriptSample, where do you use?

0 votes
Jon Starbird
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.
March 25, 2014
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)
	}}
0 votes
Jon Starbird
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.
March 25, 2014
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:
0 votes
rsud March 25, 2014

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

0 votes
Jon Starbird
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.
March 25, 2014

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

0 votes
rsud March 25, 2014

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

0 votes
Jon Starbird
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.
January 8, 2013

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

0 votes
Jon Starbird
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.
January 7, 2013

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

Thanks,

J

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events