scriptrunner formfield

i want to remove an option from a select list (for example, if user isnt a manager, dont show option X)

can i do this using behaviors and the FormField class?

also, i can seem to find any API for the groovy-jira class "FormField"

2 answers

2 accepted

1 vote
Answer accepted


thanks for the response. Forget my "manager condition". What im really having trouble with is to be able to remove an option from a select list.

also, ive been to those pages and they have some specific examples of using FormField but there is no form API page (such as this

Unfortunately there isn't currently any published API for Behaviours or the plugin's classes. If you'd like some auto-completion for coding purposes, you could put this at the top of your code to access all of the FormField methods:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

Aside from that, you could unzip the ScriptRunner executable jar file and take a look at the Behaviour classes themselves. Additionally, there is some documentation provided below the inline script box when editing a serverside script.

As for removing options from select lists, the process is a bit complex, but defintely doable. 

I've written and tested an example here that has worked for me to set the field options. If something isn't clear in the code, don't be shy to ask questions:

import com.atlassian.jira.component.ComponentAccessor

def cfm = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def formField = getFieldById(getFieldChanged())
//Custom Field version of the form field
def customField = cfm.getCustomFieldObjectByName("Custom Field Name")
def fieldConfig = customField.getRelevantConfig(issueContext)
def cfOptions = optionsManager.getOptions(fieldConfig)

//options that you want to be available to choose from
//Just the values, not the keys/IDs
def optionSet = ["Option 2","Option 3","Option 4"] //Example options

//Retrieve all of the options that you want and create a map of their ids and values.
//Set the field using those maps
formField.setFieldOptions(cfOptions.findAll{it.value in optionSet}.collectEntries{[(it.optionId) : it.value]})

yes, ive previously worked with select fields and their options. I was just unsure as to exactly how to deal with this with a formfield. i will try it. thanks

Hey Lance!

This shouldn't be too hard to accomplish with Behaviours. The best place to look for use of the API would probably be through the ScriptRunner documentation here & here.

But, if you elaborate just a little for me I can come up with a working example for you! :)

The case that you mentioned was if the "user isn't a manager." What do you mean by this? Do you mean if the user isn't a project manager, or some other custom project role or JIRA group? 

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