1

I have the following query in my code:

DynamicQuery journalArticleDynamicQuery = JournalArticleLocalServiceUtil.dynamicQuery();

journalArticleDynamicQuery.add(PropertyFactoryUtil.forName("DDMStructureKey").eq("MY_STRUCTURE")); 
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.GROUP_ID).eq(groupId));
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.FOLDER_ID).eq(folderId));
journalArticleDynamicQuery.add(PropertyFactoryUtil.forName(Field.STATUS).eq(0));
journalArticleDynamicQuery.addOrder(OrderFactoryUtil.desc(Field.DISPLAY_DATE));

JournalArticleLocalServiceUtil.dynamicQuery(journalArticleDynamicQuery, 0, 30)

But this is returning all versions of the JournalArticle. My question is: how can I query only the latest version of the JournalArticle using the previous query?

I have posted this in the Liferay Foruns but I didn't get any response yet.

Ravers
  • 988
  • 2
  • 14
  • 45
  • +1 just for crossreferencing ;). In the meantime the discussion has started on the linked Liferay forum thread. – Olaf Kock Oct 28 '19 at 16:09

1 Answers1

0

I have found out that if you use the "search" method and pass the "version" parameter as null, you get only the latest versions of the JournalArticle:

List<JournalArticle> journalArticles = JournalArticleLocalServiceUtil.search(
    themeDisplay.getCompanyId(), 
    themeDisplay.getScopeGroupId(), 
    folderIds,
    JournalArticleConstants.CLASSNAME_ID_DEFAULT,
    null,
    null,
    null,
    null,
    null,
    "MY_STRUCTURE",
    null,
    myDate,
    null,
    0,
    null, 
    true,
    startIndex,
    endIndex,
    OrderByComparatorFactoryUtil.create("JournalArticle", Field.DISPLAY_DATE, false)
);
Ravers
  • 988
  • 2
  • 14
  • 45