How to Implement Notifications with Liferay Objects: A Step-by-Step Guide

blog-banner

Liferay allows easy sending of user and email notifications through Liferay Objects by using notifications templates, without the need for coding. However, while this system works well for basic notifications triggered by actions like creating or updating objects, it doesn't support advanced scenarios like notifying multiple users based on specific conditions. Businesses need more control over who gets notified and when, ensuring the right people receive relevant alerts. This blog explores how to implement and customize these notifications effectively, ensuring timely communication for various business needs. 

Prerequisites 

  1. Liferay Portal 7.4+

  2. Objects

Creating an Object in Liferay 

What is Object in Liferay? 

Liferay object is a way of creating a custom entity without requiring custom coding or module deployment. You can learn more in our blog on creating and managing objects in Liferay.

To make a new object in Liferay, follow these steps: 

  1. Navigate to the Control Panel.  

  2. Navigate to Objects under the Object section. 

  3. Click Create New Object and add basic fields such as name, email, and phone number.  

  4. Once the object is configured, publish it. 

Create Notifications

In Liferay, you can send notifications in two ways: User Notifications and Email Notifications. 

After creating the object, follow these steps to creating notifications: 

  1. To configure these notifications, follow these steps: 

  2. Navigate to the Control Panel. 

  3. Go to Notifications and then select Template. 

  4. In the Template section, you can create and manage: 

  5. User Notifications  

  6. Email Notifications 

Create User Notifications: -  

User Notification
 

We are creating user notifications for sending notifications to Liferay users. 

To create a template using User Notifications, follow these steps: 

Click on the Plus (+) Button and select User Notification.  

Mail Notification
 

Basic Info Section

  • In this section, you need to add a Name and a Description for the template.   

Settings Section 

Under Recipients in the Settings section, you can choose User, Role, or Definition Term. 

  • User: If you choose User, you can select individual users from this site. The selected users will be notified when an object entry is created.  

  • Role: If you choose Role, you can specify a role from this website. Notifications will be sent to users belonging to the role when an object entry is added. 

  • Definition Term: In Definition term we can add dynamic values. In the sections below are general terms provided and any specific terms we need from object so we can get from Entity Dropdown.  

Content Section

  • In the Content section, we have the Subject field. In this field, you can add the subject of the template.  

Content Section
 

Definition Term: - In definitions terms there are general terms and Entity Dropdown. You can find your custom-created object in the Entity Dropdown. Simply select your object, and all the object fields will be available directly. 

Once you’re done with all the template configurations, save the template. 

Hire liferay developer

Creating Object Actions to trigger User Notification.  

Creating Object Actions to trigger User Notification.
 

  1. Navigate to the object you created earlier.  

  2. Go to the Action tab in the object and create a new action. 

  3. Using the Action Builder, Select the Trigger when you are triggered and below Action select Notification and User Notification template also. 

Checking User Notifications in Liferay

After completing the setup, add a new entry to the object. Once the new entry is added, navigate to the home page. Click on the User Profile button, and you can check the Notifications tab. 

Checking User Notifications in Liferay
 

Checking User Notifications in Liferay
 

Email Notifications Template: 

If you want to send email notifications to users using object actions, follow these steps: 

Create New template Using Email Notifications.  

Email Notifications Template
 

Email Notifications Template
 

Basic Info Section:  

  • Add the name and description of the template. 

  1. Settings Section: 

  • Add the recipient's email address in the "To" field. 

  • If needed, you can also add CC and BCC email addresses. 

  • Specify the "From" address and the sender's name

Content Section:  

  • Add the email subject.  

  • In the editor, you can choose between rich text and free markup formats.  

  • The content you add in this section will be used as the body of the email.  

  • We have an attachment field in Object and want to send in email, you can directly select it and send it to the user. 

    Email Notifications Templates
     

  • In the Definition of Terms section, you can access dynamic fields from your object. This allows you to insert values like the user's name, email address, or any other object-related data into the email template dynamically.  

Transform Your Digital Experience with Liferay

Mail Configurations: - 

Follow the steps below to set up the SMTP configuration: 

Navigate to the: - Control Panel → Server Administration → Mail 

In the Outgoing SMTP Server section, fill in the following properties:   

Mail Configurations Screen

 

  • Outgoing SMTP Server: [Your SMTP server address] 

  • Outgoing Port: [SMTP port number] 

  • Use a Secure Network Connection: (Enable this if your SMTP server requires SSL or TLS) 

  • Enable STARTTLS: (Check this if your server supports STARTTLS) 

  • Username: [Your email address] 

  • Password: [Your email password or app-specific password] 

Creating Object Actions to trigger Email Notification.

Creating Object Actions to trigger Email Notification.
 

Creating Object Actions to trigger Email Notification.
 

  1. Navigate to the object you created earlier.  

  2. Go to the Action tab in the object and create a new action. 

  3. Using the Action Builder, Select the Trigger when you are triggered and below Action select Notification and Email Notification template also. 

Now add a new Object Entry and it will send Email to the recipient Users. 

Conclusion

Liferay 7.4 allows you to send user and email notifications without writing any custom code. By creating custom objects and using built-in notification templates, we can send user and email notifications. We can send notifications to specific users, roles, or dynamic recipients using object fields. 

Contact us

For Your Business Requirements

Contact us