Accessing the Display Value of the Selected Item(s) in a List Field
When your object contains a single-selection fixed-choice list field named SomeListField, you can use the getSelectedListDisplayValue() function to access the description that corresponds to the current field's code value.
The function takes a single argument that is the name of the list field for whose selected value you want the description. For example, consider a single-selection fixed-choice field called RequestStatus. You could write conditional logic based on the selected status' description string using code like this:
def meaning = getSelectedListDisplayValue('RequestStatus')
if (meaning.contains("Emergency")) {
// do something here when description contains the string "Emergency"
}
If your object contains a multiple-selection fixed-choice field named
MultiChoiceField
, you can use the
getSelectedListDisplayValues()
function to access a list of the
descriptions that correspond to the current field's one or more selected code values. As
above, the function takes a single argument that is the name of the multiple-selection
fixed-choice list for whose selected values you want the descriptions. For example, consider a
custom multiple-selection fixed-choice list named Category_c
. You could write
conditional logic based on the selected status' description string using code like this:
// return true if any of the selected meanings contains the
// string "wood" case-insensitively (using Groovy regular expressions)
def meaningsList = getSelectedListDisplayValues('Category_c')
for (meaning in meaningsList) {
// if current meaning contains "wood" case-insensitively
if (meaning =~ /(?i)wood/) {
return true
}
}
return false
If you call the multi-selection list function getSelectedListDisplayValues()
on a single-selection list field, it returns a list containing a single value. If you call the
single-selection list function getSelectedListDisplayValue()
on a
multi-selection list field, it returns the String value of the first of the multiple choices
selected. If you call either of these functions on a list field whose value is
null
or whose value is not a valid choice for the list, then the function
returns null
.