ETP-2900: Fixing Automatic Task Creation & Assignment

by Alex Johnson 54 views

This article delves into the intricacies of the ETP-2900 issue, which causes incorrect automatic task creation and user assignment within the Etendo platform. Specifically, this problem manifests in the com.etendoerp.task module and stems from two key areas: the handling of null filter fields and the use of an incorrect createTask overload. Understanding these issues is crucial for maintaining the efficiency and accuracy of task management within Etendo.

Error Description: Two Core Issues in Automatic Task Creation

The com.etendoerp.task module, responsible for automatic task creation based on Task Types and their Table rules, contains two primary issues. Let's break down each one in detail:

1. Filter Field Null Handling: The Case of the Missing Tasks

In the Task Type window, under the “Table” tab, a critical flaw emerges when the Filter field is left null or empty. The TaskTypeMatchJob validation process incorrectly interprets this null value as false, leading to the rule being skipped entirely. As a result, no task is created, which deviates from the intended functionality.

The current logic snippet illustrates this issue:

if (!TaskUtil.validateFilter(rule.getFilter(), after)) {
 continue;
}

This code block treats an empty filter as a “do not match” condition. However, the desired behavior is for an empty filter to signify a universal match, effectively acting as true. This would ensure that tasks of the specified type are always generated for a given table, irrespective of additional conditions. For instance, an “Email sending” task should be created every time a new record is added to the C_Order table, without any further filters applied. The importance of this fix lies in streamlining task creation for scenarios where tasks need to be generated consistently without specific conditions.

2. Incorrect TaskUtil.createTask Overload: The Admin User Anomaly

When a task is automatically created—that is, when it successfully passes the validations in TaskTypeMatchJob—the system employs a flawed TaskUtil.createTask overload. This leads to an unintended consequence: tasks are invariably assigned to the Admin user. This behavior contradicts the expected functionality, which dictates that tasks should be assigned to the appropriate user based on the defined assignment algorithm. The current code calls the following method:

public static Task createTask(Table rule, State initialState, JSONObject data, JSONObject rawEvent,
 boolean createdAutomatically)

This method bypasses the automatic assignment process, leading to the incorrect assignment of tasks. The correct method to be used is:

createTask(TaskType taskType, Status status, boolean assignOperatorAutomatically,
 JSONObject parameters, OBContext entityContext)

This method ensures that the task is automatically assigned according to the defined rules, aligning with the intended functionality of the system. Using the correct method ensures that tasks are routed to the appropriate users, improving workflow efficiency and task management.

Steps to Reproduce the Errors: A Hands-On Guide

To fully grasp the implications of these bugs, it’s essential to understand how to reproduce them. Here’s a step-by-step guide:

Bug 1: Filter Null Treated as False

  1. Log into Etendo with a role that has the necessary permissions to configure Task Types and test events.
  2. Navigate to the Task Type window.
  3. Create a new Task Type (or use an existing one if available).
  4. Go to the “Table” tab and follow these steps:
    • Select a table (e.g., C_Order).
    • Leave the Filter field empty/null. This is the critical step for reproducing the bug.
    • Configure the remaining fields as required to ensure that a task should be created when a new record is inserted (e.g., set automatic creation on insert).
  5. Ensure that there is no advanced logic configured that would block task creation. Alternatively, configure a trivially true advanced logic to bypass any potential blocks.
  6. Create a new record in the configured table (e.g., a new C_Order).
  7. Check the Tasks window.

Current Result:

When the Filter is empty, no task is created upon record insertion. This is because TaskUtil.validateFilter(rule.getFilter(), after) returns false (or the logic treats null as false), causing TaskTypeMatchJob to skip the rule.

Bug 2: Wrong createTask Overload for Automatic Tasks

  1. Use the same configuration as in Bug 1 or:
    • Configure a Task Type and its Table rule.
    • Set a valid Filter that matches some records.
    • Configure Advanced Logic (if used) to return true for the test record.
  2. Create or modify a record such that:
TaskUtil.validateFilter(rule.getFilter(), after) returns true;
TaskUtil.executeAdvancedLogic(rule, after) returns true;
  1. Allow the TaskTypeMatchJob to run.
  2. Inspect the created task.

Current Result:

The task is consistently assigned to the ADMIN user, regardless of the intended assignment rules.

Required Configurations: Setting the Stage for Reproduction

To accurately reproduce these errors, certain configurations must be in place:

  • The Platform bundle must be installed.
  • The com.etendoerp.task module must be installed and active. This module is the core of the task management functionality.
  • You need access to the Task Type window to configure Task Types and Table rules. Additionally, access to the table chosen in the Table tab (e.g., C_Order) with the permission to create records is necessary.
  • The TaskTypeMatchJob needs to be configured and running. This involves:
    • Setting up topics for each async job created from the states available in your task type.
    • Ensuring a topic for the etask_task table is created (default.public.etask_task).

Expected Behavior: Correcting the Course

To rectify the issues, the expected behavior needs to be clearly defined for both scenarios:

1. Filter Null/Empty Behavior: The True Meaning of Empty

When the Filter field in the Table tab of the Task Type window is null or empty, the system should interpret this as Filter = true. In other words, the rule should always match as long as the table is the configured one.

TaskUtil.validateFilter(rule.getFilter(), after) should effectively behave as true when rule.getFilter() is null or empty. Consequently, the TaskTypeMatchJob should not skip the rule but should proceed to advanced logic (if configured) and task creation. This ensures that tasks are generated consistently when no specific conditions are required.

2. Correct createTask Overload for Automatic Creation: Assigning to the Right User

When both of the following conditions are met:

TaskUtil.validateFilter(rule.getFilter(), after) == true
TaskUtil.executeAdvancedLogic(rule.getFilter(), after) == true

the job responsible for creating tasks automatically should invoke:

createTask(TaskType taskType, Status status, boolean assignOperatorAutomatically,
 JSONObject parameters, OBContext entityContext)

This method should be called using the appropriate TaskType, initial Status, automatic operator assignment flag, parameters, and OBContext. The expected outcome is that the task is automatically assigned based on the assignment algorithm defined for its task type. This ensures that tasks are routed to the correct users, enhancing workflow efficiency and accountability.

Affected Versions: Identifying the Scope

This issue affects the following versions of Etendo:

  • Etendo 24x
  • Etendo 25x
  • Platform bundle

The bug has been identified in both the 24.x and 25.x lines, highlighting the widespread impact of this issue. Confirming the exact subversions will be necessary once the fix is backported or merged to ensure comprehensive coverage.

Conclusion: A Path to Accurate Task Management

The ETP-2900 issue presents significant challenges to the accurate and efficient automatic task creation and user assignment within Etendo. By addressing the handling of null filter fields and correcting the createTask overload, Etendo can ensure that tasks are generated under the right circumstances and assigned to the appropriate users. This resolution will improve workflow management, reduce manual intervention, and enhance the overall user experience.

For further reading on task management best practices, you can visit the Project Management Institute website. This resource offers a wealth of information on project management methodologies, including task management strategies, that can complement the solutions discussed in this article.