Leveraging Liferay’s Scripting Console

Liferay Scripting Console

Recently, we were faced with a challenge. We were trying to add a new page to Liferay with a specific name friendly URL but when we went to add the page we saw an error indicating the URL was already in use.

Screen Shot 2014-11-12 at 9.36.41 AM

This particular site has hundreds of pages and the friendly URL didn’t appear to match any existing pages. We spent a few minutes clicking through trying to locate the conflicting page without any luck. We followed the link lead to a PDF on the site but the page name used to configure it still wasn’t obvious. We needed a better approach to solve this.

Enter Liferay’s scripting console.

Screen Shot 2014-11-12 at 9.39.04 AMIn version 6.0, Liferay added a scripting console to the Server Administration section of the control panel. This is a powerful tool that we frequently use during development, debugging and prototyping.  This was the perfect place to run a quick query to figure this out.

We wrote a simple groovy script. Given a friendly URL this script will return the associated page name.

import com.liferay.portal.service.LayoutLocalServiceUtil

friendlyURL = ‘/third-quarter-report’

groupId = 10182

boolean privateLayout = false;

layout1 =

LayoutLocalServiceUtil.getFriendlyURLLayout(groupId, privateLayout, friendlyURL)

out.println(layout1.getFriendlyURL() + ‘ : ‘ + layout1.getName());

Screen Shot 2014-11-12 at 9.58.33 AM

We ran the script, identified the conflicting page and worked with the marketing team to resolve the conflict.

Liferay’s scripting console has uses beyond simple queries. We also use it for:

  • Bulk user maintenance
  • Automating setup and configuration steps such as creating pages, users and roles
  • During development to quickly test Liferay APIs and verify results
  • As a rapid prototyping tool during development
  • Scripting repetitive operations and maintenance tasks
  • More complex queries to identify and resolve issues

The scripting console is a powerful feature within Liferay and shouldn’t be overlooked. For more information refer to:

Was this information useful? Share your comments below.