formField.getValue() Select List as string

Fredrik Ivansson Flinta December 5, 2019

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
Will C
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.
December 6, 2019

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}")
Fredrik Ivansson Flinta December 6, 2019

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?!

Fredrik Ivansson Flinta December 6, 2019

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 :)

Will C
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.
December 6, 2019

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.

Suresh Srini December 14, 2020

I am trying to read the value from priority field for my comparison statement and for next step of operation. By using above method, I am not able to get the value  "low, Medium, etc". Results shows me bigger string with all values.

 

IssueConstantImpl[[GenericEntity:Priority][sequence,4][statusColor,#0065ff][name,Low][iconurl,/images/icons/priorities/low.png][description,Minor problem or easily worked around.][id,4]]


Can you suggest me a way around?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events