Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need doc for Scriptrunner behaviours convertToXSelect() methods and ajaxOptions parameter

Eddy Fras
Contributor
May 25, 2020

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

1 answer

1 vote
PD Sheehan
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.
May 26, 2020

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'])

 

Eddy Fras
Contributor
June 2, 2020

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.

Eddy Fras
Contributor
June 8, 2020

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

PD Sheehan
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.
June 8, 2020

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]})
Eddy Fras
Contributor
June 9, 2020

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 ...

Eddy Fras
Contributor
June 9, 2020

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 ...

PD Sheehan
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.
June 9, 2020

Here is an example (latest scriptrunner version)

2020-06-09 08_10_57-Edit Behaviour_ jsp test.pngYou can see that when I use ctrl-p in the convertToSingleSelect, there is an option with "no arguments".

This looks like this in jira:

2020-06-09 08_17_25-Edit Issue _ JSP-1922 - JIRA Dev - https___projects-dev.qad.com_browse_JSP-1922.png

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'])

 

Antoine _Klee Group_
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 1, 2024

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.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.3
TAGS
AUG Leaders

Atlassian Community Events