Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

formField.getValue() Select List as string

Hi all

 

A hopefully simple question, how do I get the selected value in a Select List as a String in a behaviour server-side script?

 

def Field = getFieldById("customfield_nnnnn").getValue() returns an array but I would like to get it as a String to use further on in a select list conversion JQL.

 

Thanks in advance!

1 answer

1 accepted

0 votes
Answer accepted

you should be able to call .toString() on the end of your .getValue() which will convert it to a string.

so 

getFieldById("customfield_nnnnn").getValue().toString()

Heres an example of mine that works:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

FormField field = getFieldById(getFieldChanged())
def description = getFieldById("Description")
def ragO = getFieldByName("customFieldName")
def ragV = ragO.getValue()
def ragS = ragV.toString()
description.setFormValue("${ragS}")

Thanks for the reply, almost got it.

ragS will return [2] ( the "2" is the value from the customfield ragO).

Seems like it returns a list or collection?!

Solved it :)

def cf= getFieldById("customfield_16024").getValue()

def cfString = cf.toString().getAt(1) 

getAt access the index at position 1 and thats exactly what I want.

Thanks @Will C for getting me in the right direction :)

Sorry I read your question as you wanted to get the value as a string, I didn't realise you needed to get certain parts of the string. as long as you go there in the end.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

5 mobile apps for Jira Cloud to boost productivity

  It’s very important to have access to the workflow process from anywhere. Especially if you manage the work of others. There is no difference whether you’re out of office, or drive a ca...

249 views 2 5
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