Adaptavist documentation gives some examples on conversions in behaviours here : https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html
But I can't find any doc for convertToXSelect() methods in https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html
Is it somewhere else ?
What I definitely miss is an exhaustive list of parameters we can set in ajaxOptions, the defaut values, etc.
Does someone have this information ?
Thanks
I'm not aware of any documentation other than what you already have links for.
I am only aware of
[ ajaxOptions:
[
url: "string",
query: true/false,
minQueryLength: int,
keyInputPeriod: int,
data: [ //map object of query parameters to include in the rest request
],
formatResponse: "general|issue"
],
css: "css style string"
]
One thing to know that's not clear from the documentation is that once you've converted the field to a select, you can then use the setFieldOptions method. So depending on what your data source is, maybe you don't need to make ajax request, instead, hard code the list:
field.convertToSingleSelect().setFieldOption(['':'None", 'option1Value':'Option1 Label'])
Thanks Peter for your reply but I definitely need to make a REST call to get data and populate the field options.
So if some Adaptavist expert can help us and provide more doc on that point, that would be great.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
I tried your suggestion to hard code the list of options for another need but it didn't work for me.
It seems that we need a List of Options objects in the setFieldOptions() method :
{code}
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.fields.ImmutableCustomField.setFieldOptions() is applicable for argument types: (LinkedHashMap) values: [[:None, option1Value:Option1 Label]]
{code}
Did you test this on a recent Scriptrunner version ?
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What you are attempting to do is apply a scriptrunner behavior method to jira customField object.
The setFieldOption will only work within a behavior server-side script and only on a com.onresolve.jira.groovy.user.FormField object.
def myFormField = getFieldByName("A custom text field name")
myFormField.convertToSingleSelect().setFieldOptions(['':'None", 'option1Value':'Option1 Label'])
This is for a case where you are converting a text field to a SingleSelect field.
If you have a custom select field and you want to manipulate the list of available options (you can only remove, you can't add new options that don't exist in the custom field configuration), you can do something like this:
def fieldName = "A custom single select field name"
def myFormField = getFieldByName(fieldName)
def customField = customFieldManager.getCustomFieldByName(fieldName)
def config = customField.checkCf.getRelevantConfig(issueContext)
def allOptions = optionsManager.getOptions(checkConfig)
def optionValuesToShow = ['OptionA', 'OptionB']
def optionsToShow = allOptions.findAll{it.value in optionValuesToShow}
myFormField.setFieldOptions(optionsToShow.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.
Thanks a lot Peter for this explanation.
I read something about that somewhere else in the community posts (https://community.atlassian.com/t5/Adaptavist-questions/Adaptavist-Sriptrunner-for-jira-server-What-bindings-I-can-use/qaq-p/1104858) and I definitely agree : Scriptrunner is a very powerfull tool but the documentation misses a lot of important details ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Testing your code in a behaviour, it seems that convertToSingleSelect() method can't be called without any parameter.
The JS console throws :
Uncaught (in promise) TypeError: Cannot read property 'minQueryLength' of undefined
If I add an empty parameter, convertToSingleSelect([ajaxOptions:[]]), the field is converted to a select but it keeps searching for nothing ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is an example (latest scriptrunner version)
You can see that when I use ctrl-p in the convertToSingleSelect, there is an option with "no arguments".
This looks like this in jira:
I did have an error in the earlier code where I used a double-quote to close a single-quote.
Here is the corrected code block:
def myFormField = getFieldByName("A custom text field name")
myFormField.convertToSingleSelect().setFieldOptions(['':'None', 'option1Value':'Option1 Label'])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan, your code works fine but the behaviour only works in the "jira agent interface", not on the portal, in Jira service management projects.
Even though I did a "Use Service Desk mapping" for this behaviour.
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.