Skip to content

Instantly share code, notes, and snippets.

@pedroblandim
Created May 10, 2022 22:50
Show Gist options
  • Save pedroblandim/c8591ddaaa3bdfd066e50d5793601a24 to your computer and use it in GitHub Desktop.
Save pedroblandim/c8591ddaaa3bdfd066e50d5793601a24 to your computer and use it in GitHub Desktop.
Liferay: Get Journal Article's DDM Field value
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)
@marcosblandim
Copy link

marcosblandim commented Jun 13, 2023

You could get both DDMFormValues and DDMFormFieldValuesMap directly from the Journal Article:
def ddmFormFieldValuesMap = ja.getDDMFormValues().getDDMFormFieldValuesMap();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment