I have created a Liferay WCM structure with a field where the user enters the ID of an existing web content. I want to use that ID to get the resource UUID.
How can I accomplish this?
I followed the help of Parkash Kumar using the FreeMarker language instead of Velocity and it works but using Id:
<#assign EntryId = 456017 /><#-- id -->
<#assign EntryArticleId= 444831 /><#-- articleId -->
<#assign articleId = EntryId?number />
<#assign articleService = objectUtil("com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil") />
<#assign article = articleService.getJournalArticle(articleId) />
<#assign articleResourceId = article.getArticleResourceUuid() />
When I use articleId
I get this error:
com.liferay.portlet.journal.NoSuchArticleException: No JournalArticle exists with the primary key 444831
First of all locate JournalArticleLocalServiceUtil
using $serviceLocator.findService
method and
#set($articleService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil"))
then use getArticle
method to get article by id (primary key) / articleId, as following:
#set($id = xxx) here `xxx` is your `$id (primary key)`
#set($articleById = $articleService.getArticle($id))
#set($articleId = xxx) here `xxx` is your `$articleId`
#set($articleByArticleId = $articleService.getArticle($groupId, $articleId))
Now, you can access all the properties of $article
object:
#set($articleResourceId = $article.getArticleResourceUuid())
#set($articleUUId = $article.getUuid())