Getting the value chosen by user in a 'Select From List' field
How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!
While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.
legacy-article
learn-legacy-article-disclaimer-text
Issue
- How to get the value from the options added in a 'Select From List' field? We are getting the reference (i.e. ["Option37425674"]) instead of the value chosen by the user.
Resolution
- Following example can be used as reference (it is a Widget Template of type Search Results Template):
<#if entries?has_content>
<#list entries as entry>
<#if entry.getClassName() == "com.liferay.journal.model.JournalArticle" >
<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") />
<#assign journalArticle = journalArticleLocalService.getLatestArticle(entry.getClassPK())/>
<#assign ddmStructure = journalArticle.getDDMStructure() />
<#assign ddmForm = ddmStructure.getDDMForm()/>
<#assign ddmFieldLocalService = serviceLocator.findService("com.liferay.dynamic.data.mapping.service.DDMFieldLocalService")/>
<#assign ddmFormValues = ddmFieldLocalService.getDDMFormValues(ddmForm, journalArticle.getId()) />
<#assign ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues() />
<#list ddmFormFieldValues as fieldName>
<#assign ddmFormFieldOptions = fieldName.getDDMFormField().getDDMFormFieldOptions() />
<#assign optionsValues = ddmFormFieldOptions.getOptionsValues() />
<#assign options = ddmFormFieldOptions.getOptions() />
<#list optionsValues as optionValue>
<#if fieldName.getFieldReference() == 'Select78866849'>
<#if optionValue == fieldName.getValue().getString(locale)?remove_beginning("[\"")?remove_ending("\"]") >
<#list options as k, v>
<#if optionValue == k >
Option ${fieldName.getValue().getString(locale)} has ${v.getString(locale)} as value
</#if>
</#list>
</#if>
</#if>
</#list>
</#list>
</#if>
<p> </p>
</#list>
</#if>
did-this-article-resolve-your-issue