Is it possible to extract articleId from portletId in Liferay 7.4 GA93 ?

Jamie Sammons, modified 1 Year ago. New Member Posts: 12 Join Date: 4/18/24 Recent Posts

Hi All,

Recently we have upgraded our portal from Liferay 7.0 to 7.4.3.GA93 and I'm facing some issue with retrieving articleId from portletId. Could someone help me to resolve this issue ?

Liferay Version : 7.4.3.GA93

PortletId : com_liferay_journal_content_web_portlet_JournalContentPortlet_INSTANCE_Bfiqq81RX0Hn

I have checked the portletpreferences and journalarticle table and I don't see any relation between these tables. Is it possible to retrieving articleId from Liferay API using portletId or plid(Layout ID)?  Please suggest me some work around for this issue.

Jamie Sammons, modified 1 Year ago. New Member Posts: 2 Join Date: 6/26/24 Recent Posts

Hello,

To retrieve the article Id from the portlet Id in Liferay 7.4 GA93, you can use the Liferay API, as there isn't a direct relationship in the database tables. Instead, you can access the PortletPreferences associated with your portletId.

First, use PortletPreferencesLocalServiceUtil to get the portlet preferences for your specific portletId and layout ID (plid). Here’s a quick code snippet:

long plid = // your layout ID (plid)

String portletId = "com_liferay_journal_content_web_portlet_JournalContentPortlet_INSTANCE_Bfiqq81RX0Hn";

PortletPreferences portletPreferences = PortletPreferencesLocalServiceUtil.getStrictPreferences(plid, portletId);

Next, extract the articleId from these preferences:

String articleId = portletPreferences.getValue("articleId", null);

if (articleId != null) {

    System.out.println("Article ID: " + articleId);

} else {

    System.out.println("Article ID not found in portlet preferences.");

}

This method should help you retrieve the articleId you need.

Hope it helps !

 

 

Thank you