How To Apply Workflow With Custom Entity And Round Robin Assignment In Liferay DXP?

How-To-Apply-Workflow-With-Custom-Entity-And-Round-Robin-Assignment-In-Liferay-DXP
Blogs

How To Apply Workflow With Custom Entity And Round Robin Assignment In Liferay DXP?

Organizations use workflows to coordinate tasks between people and synchronize data between systems, with the ultimate goal of improving organizational efficiency, responsiveness, and profitability. Liferay Digital Experience Platform provides an opportunity for enterprises to boost their businesses with co-ordinated workflows.

Liferay DXP provides easy integration of workflow on various out-of-the-box assets like blog, wiki, users, web contents, documents, etc. However, in many scenarios, businesses need to implement workflow on custom entities. Liferay DXP Platform provides support for this. In short, you can implement workflow on your own entities by following the below steps.

  1. To make the Custom Entity as Asset Type,
    • Insert asset entry reference in service.xml for the custom entity.
    • Add columns workflow status, user id, and date in custom entity definition.
    • While adding a custom entity, add an entry of it in asset local service.
  2. To make it available for Workflow,
    • Define workflow handler class.
    • Implement update status method in workflow handler class to update the status of workflow as per the task assignment.
  3. To make it visible for Workflow Configuration Screen,
    • Define asset render class for a custom entity.
    • Define asset render factory class.
  4. To start Workflow,
    • Add start workflow instance method while adding custom entity or any event on which workflow should start.
    • Add method for updating assets in asset local service.
  5. To configure it in Control Panel,
    • Go to control panel >> workflow configuration, check your custom entity, and apply the workflow.

Read more about: 12 Must Have Features Of Liferay Portal Development

How to Implement Round Robin Task Assignment to user in Workflow in Liferay DXP?

Liferay out of the box provides facility to assign task to user groups, roles, roles type or user in workflow. Many a times in public sectors where the task assignment based on work load is required, there is a need of round robin task assignment.

If the task is assigned to roles, then users of that roles will have to assign to him/her self. If the task is assigned to user, only one user will get the task. But if there are multiple users in single role and requirement of task assignment based on simultaneous process than there is no out of the box facility available. In this case requires algorithm of round robin. Below figure shows how the round robin task assignment work. For example, let’s take three users. User1, User2 and User3.

As shown in figure, task assignment will be simultaneously, it means first task will be assigned to user1, next task will be assigned to user2, next will be assigned to user3, again process repeat next will be assigned to user1 and so on.

These kinds of structure requires Round Robin Algorithm. Below are the steps to implement Round Robin Algorithm in Workflow.

Liferay-DXP-Workflow

As shown in figure, task assignment will be simultaneously, it means first task will be assigned to user1, next task will be assigned to user2, next will be assigned to user3, again process repeat next will be assigned to user1 and so on.

These kinds of structure requires Round Robin Algorithm. Below are the steps to implement Round Robin Algorithm in Workflow.

Step 1: Configure new entity in service.xml for task assignment. Build and Deploy it.

For example,
Code Snippet:
liferay_dxp_1

Step 2: Define finder method in tasklocalserviceimpl.java.

For example,
Code Snippet:
liferay_dxp_2

Step 3: Create workflow.xml from Kaleo Designer in Control Panel. For task assignment select scripted assignment. And add below suggested script in it.

In Script,

  • Get User List of Role1.
  • Get List of tasks by role id and status(True).
  • If task list is empty, then add user in task table and update task list.
  • Check if user is removed from that roles and still status of task is True than make it False and again update task list.
  • Check if new user is added in to roles and it’s not available in task than add that user in task table and update task list.

Code Snippet:

liferay_dxp_3png

Step 4: Apply this work-flow to your entity from work-flow Configuration.

For Example, this workflow is applied to a custom entity, let’s say “Leave Request,” To check this workflow is running, create a leave request from the regular user and check every user’s task list or notification. It will assign tasks based on the simultaneous process, so in the above example case, User1 will get the task, and the rest will not be notified.

After that, create another leave request from the regular user and check every user’s task list or notification. It will assign tasks to User2, and the rest will not get notified. So, on the task assignment will be performed.

Liferay Performance Tuning or Liferay Portal Development, we at Anblicks have the expertise and experience to deal with all Liferay Migration from 6.0 to DXP and from one technology to another, with zero data and time loss. Contact us for a free consultation for all your Liferay-related queries.