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"
hello,
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 https://docs.atlassian.com/jira/6.4/)
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]})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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.