Mastering Data Modeling with Liferay Objects

Course Overview

Understanding Object Actions

Object actions in Liferay empower you to automate and streamline operations within your application. By defining specific triggers, conditions, and actions, you can implement business logic that responds to user interactions or system events, without requiring manual input at every step.

Elements of an Object Action

When defining an object action, you configure these essential elements:

  • Trigger: Determines when the action executes.

  • Condition (Optional): Defines additional rules that determine when the action executes.

  • Action: Defines the task executed when the trigger is activated and the specified conditions are met.

When defining an object action, you configure the trigger, condition and action.

These elements provide granular control over object business logic, enabling you to tailor its behavior to your specific needs. Whether you're automating workflows, updating records, or sending notifications, object actions offer flexibility and control.

Here you’ll explore each component in detail, demonstrating how to leverage them to automate processes, ensure data integrity, and enhance user experiences.

Triggers

The trigger defines the event that initiates the action. Triggers can be automatic or manual. Most options are available for all object definitions, though some are only available for specific system objects.

Here’s a list of available triggers:

Trigger Description
On After Add When an entry is added
On After Attachment Download When an entry attachment is downloaded
On After Delete When an entry is deleted
On After Update When an entry is updated
Standalone Triggered manually or programmatically
On Order Status Update* When an order status is updated
On Payment Status Update* When the payment status of an order is updated
On Subscription Status Update* When the subscription status of an order is updated

* Available only for the Commerce Order system object.

Using Automatic Triggers

Automatic triggers streamline routine processes such as updating records, sending notifications, or syncing data across systems. For example, in an e-commerce system, you can automatically notify a customer when an order ships. Triggers are vital for creating event-driven architectures, where actions are initiated based on specific object events, reducing manual effort and ensuring timely execution.

Using the Standalone Trigger

The standalone trigger enables you to execute object actions using one of three methods:

  • Default Object View: Trigger standalone actions via the object's default view by clicking an entry's Actions button and selecting the desired action.

  • Page Builder Features: Trigger standalone actions via site pages by clicking button fragments that are mapped to the action.

  • Headless APIs: Trigger standalone actions using dedicated REST endpoints.

These methods provide flexibility for when user intervention is necessary or you want to trigger actions programmatically using custom solutions (e.g., client extensions). Additionally, when you define a standalone action, Liferay generates a permission for controlling who can execute the action.

Conditions

For automatic triggers, you can set conditions to further restrict when actions execute. These conditions use logical expressions to define rules for evaluating aspects of the object entry. For example, in a ticketing application, you might want to notify users only when a ticket’s status is set to ‘Closed’ or ‘Input Requested’ but not for intermediate status changes.

When you create object actions, use conditions to ensure each action aligns with your business rules to prevent unnecessary executions and optimize automation efficiency. Also, when defining conditions, prioritize simplicity and clarity to improve maintainability and ensure a clear understanding of your action's behavior.

Actions

The action defines “what” is performed when the trigger is activated, and the condition (if any) is met. Liferay supports the following out-of-the-box (OOTB) action types:

Action Type Description
Notifications Automatically send email or user notifications using predefined templates. These actions can help keep users informed about platform events related to object entries. For example, you could notify customers when their orders ship or administrators when new user accounts are created.
Add an Object Entry Create new entries in a specific object. For example, you can automate the creation of shipment entries when orders are paid. Similarly, you could use this action with the standalone trigger to quickly create child tickets with predefined values based on the parent ticket.
Update an Object Entry Modify fields in the current object entry. For example, you could automatically update a boolean field to ‘true’ when a user downloads an attached file. Similarly, you could use this action with the standalone trigger to quickly update a ticket's assignee to the current user.
Webhook Send a data payload to a specified URL. This enables you to integrate Liferay DXP with external systems, sending data based on object events.
Groovy Script Execute custom Groovy scripts, implementing complex logic not possible with other action types. Note that Groovy script actions are only available for Liferay PaaS and Liferay DXP Self-Hosted.

 

In addition to OOTB action types, Liferay supports Client Extensions for defining external action handlers. These handlers bind to object action events, enabling you to execute external microservices according to your set trigger and conditions. This offers a high level of logic customization, which is especially valuable for Liferay SaaS environments where Groovy script actions are unavailable.

Using Object Actions Effectively

Object actions provide significant value by enabling custom business logic. Whether you're automating approvals, syncing data, or sending user notifications, object actions empower you to make your systems more efficient and responsive. Strategically selecting triggers, conditions, and actions reduces manual effort, improves consistency, and ensures processes run as expected.

Here you’ll explore some key considerations when designing object actions for your application.

Choosing the Right Trigger

  • Use automatic triggers for processes that must happen without user interaction (e.g., sending notifications for order completion).

  • Use the standalone trigger for actions that require manual initiation (e.g., exporting reports).

  • Avoid automatic triggers for overly frequent events to reduce system overhead and performance impact.

Leveraging Conditions

  • Use conditions to fine-tune when actions execute, preventing them from running unnecessarily.

  • Prioritize simplicity and clarity to improve maintainability and ensure your action’s behavior is clearly understood.

Using Custom Actions (Groovy Scripts or Client Extensions)

  • Keep custom scripts and client extensions maintainable and well-documented.

  • Test scripts and client extensions in a dev environment before deploying them to production.

Prioritizing Data Integrity

  • Ensure actions like Update an Object Entry preserve the integrity of critical data, especially in complex systems like e-commerce.

  • Validate entries before executing actions to ensure data accuracy and prevent errors in downstream processes.

Managing Object Actions for Large Data Sets

Processing object actions for large data sets can significantly impact performance, particularly when external systems are involved (via webhooks or client extensions) or when executing complex business logic. This can lead to bottlenecks or delays in your system, especially if these external calls are synchronous or require extensive data processing.

To optimize performance and ensure stability when dealing with large data sets, consider the following best practices:

  • Split the Data into Smaller Chunks: Instead of processing the entire data set at once, break it down into smaller, manageable chunks. This helps distribute the load over time, reducing the strain on both Liferay and any integrated systems.

  • Focus Action Execution with Conditions: Leverage conditions to selectively trigger actions only when they are required and avoid unnecessary actions. For example, instead of sending data to an external system every time an object is updated, use conditions to only trigger the action for specific updates meaningful to the integration.

  • Test and Tune Performance: Regularly test the performance of object actions involving large data sets and complex logic. Monitor system logs and adjust action configurations to optimize performance. This can include optimizing webhook payloads, improving external system efficiency, or refactoring business logic to be more efficient.

By following these strategies, you can ensure that large-scale object actions execute smoothly without degrading the overall performance of your system or its integrations.

Conclusion

Object actions are fundamental for implementing business logic and automation in Liferay DXP. Thoughtful design and adherence to best practices ensure efficient, scalable, and maintainable actions that streamline processes and enhance your applications. Next, you’ll explore notification actions in greater detail.

  • Elements of an Object Action

  • Triggers

  • Conditions

  • Actions

  • Using Object Actions Effectively

  • Managing Object Actions for Large Data Sets

  • Conclusion

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy