Count Web Content Articles by Structure ID in Liferay using Groovy script

Author: Ajay Choudhary

Liferay Version: 7.3, 7.4

In Liferay, you might need to count the number of web content articles associated with a specific structure ID. This guide provides a step-by-step method using a Groovy script.

Counting Web Content Articles by Structure ID

The following Groovy script counts the number of web content articles associated with a specific structure ID:

import com.liferay.journal.service.JournalArticleLocalServiceUtil

// Replace 12345 with your structure ID
long structureId = 12345L

// Fetch all journal articles
List articles = JournalArticleLocalServiceUtil.getJournalArticles(-1, -1)

// Filter articles by structure ID and count them
int count = articles.count { it.getDDMStructureId() == structureId }

println "Number of web content articles with structure ID ${structureId}: ${count}"

Steps to Execute

  1. Go to Control Panel > Server Administration > Script.
  2. Paste the above script into the console.
  3. Click Execute.
  4. The output will display the total number of articles with the specified structure ID.

Best Practices and Warnings

Also Read: How to Fetch a Category Name Using Category ID in Liferay with FreeMarker

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

close
Thanks !

Thanks for sharing this, you are awesome !