Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set value on a field with convertToSingleSelect

I am using Scriptrunner 6.20.0 and I have converted a text Field to a SingleSelect and it displays fine, plus I can select an option in the form. Just what I wanted.

def tribeField = getFieldByName("Tribe")
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/...",
query : true,
formatResponse: "general"

The problem is that I cannot set a value in the field programmatically.

"tribe1" is one of the values returned from the REST endpoint, and I have tried many things, before or after calling convertToSingleSelect, like:

tribeField.setFieldOption(["tribe1": "tribe1"])

The second line sets an option in the hidden input HTML element, which is not valid:

<input class="text full-width-field" type="text" name="customfield_20208" id="customfield_20208" aria-labelledby="customfield_20208-label customfield_20208-helper" style="display: none;">
<option value="tribe1">tribe1</option>


This is exactly my problem, but the answer did not help at all:

Any ideas?

1 answer

0 votes

I've encountered this and raised a support request a few years back.

They pointed me to but that was ultimately fixed with the issue picker custom field rather than adjusting the convertToSingleSelect() functionality.

I never tried the solution you pointed to... I see in your example that you setFieldOption (no s) and in the linked post, they  have setFieldOptions (with s).

I would recommend you try that first.

If you can't get that to work as is... the workaround is to:

1) Call your API and load all the data into a Map object, then

2) convert your field to a single select without any parameters and set the field options from your map. 

def map =[:]
map.put("","") //include an empty choice so you can clear it
def httpBuilder = new HTTPBuilder(getBaseUrl())
httpBuilder.request(Method.GET, ContentType.TEXT) {
uri.path = "/rest/scriptrunner/latest/custom/..."
uri.addQueryParam 'pkey', project.key
headers."accept" = ""
headers."Authorization" = "Basic xxx" //api user
response.success = { response, reader ->
def jsonText = reader.text
def parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY)
def jsonResp = parser.parseText(jsonText)
map.put(it.html, it.html)
response.failure = {resp, reader ->
log.error("Getting data from ... : ${resp.statusLine}")


Or, move your custom REST API code into the behaviour and load the map directly from java api calls rather than have the server communicate with itself over http

Hi @Peter-Dave Sheehan ,

Thank you for you answer. I initially tried with setFieldOptions, setFieldOption and other methods that do not exist, with no success.

Going to your workaround, I think it should work, but I will loose the backend autocomplete feature, which I need since the list has +500 items in it and would load slow.

Initially, the field was of type text, and calling field.convertToSingleSelect() with no parameters on it fails, as the JavaScript code is trying to get the ajaxOptions parameter which does not exist. 

minimumInputLength: v.ajaxOptions.minQueryLength || 0,
//This ScriptRunner JavaScript line throws a browser error and the rendering stops.

I switched to a Single Select type field and I can populate it and change values in the field programmatically, but I lost the backend filtering. I wonder if there's a better solution.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

121 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you