Created
May 10, 2022 22:50
-
-
Save pedroblandim/c8591ddaaa3bdfd066e50d5793601a24 to your computer and use it in GitHub Desktop.
Liferay: Get Journal Article's DDM Field value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.liferay.journal.service.JournalArticleLocalServiceUtil | |
import com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil | |
import com.liferay.journal.model.JournalArticle | |
import com.liferay.portal.kernel.util.LocaleUtil | |
def fieldName = "field name" | |
def ja = JournalArticleLocalServiceUtil.fetchJournalArticle(id); | |
def entry = AssetEntryLocalServiceUtil.fetchEntry(JournalArticle.class.getName(), ja.getResourcePrimKey()) | |
def ddmFormFieldValuesMap = entry.getAssetRenderer().getDDMFormValuesReader() | |
.getDDMFormValues().getDDMFormFieldValuesMap(); | |
def locale = LocaleUtil.getDefault(); | |
def value = ddmFormFieldValuesMap.get(fieldName).get(0).getValue().getString(locale) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could get both DDMFormValues and DDMFormFieldValuesMap directly from the Journal Article:
def ddmFormFieldValuesMap = ja.getDDMFormValues().getDDMFormFieldValuesMap();