hello there,
I tried using taskCreatedAfter and taskCreatedBefore to set date range for querying historic task list, and used taskWithoutDeleteReason to remove the deleted task. A simple example as:
// using Flowable 7.0.1 in java 21
public List<HistoricTaskInstance> finishedList() {
HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
.taskWithoutDeleteReason()
.orderByHistoricTaskInstanceEndTime().desc();
// to find results started between period, not ok
taskInstanceQuery.taskCreatedAfter(DateUtils.parseDate("2025-11-28"));
.taskCreatedBefore(DateUtils.parseDate("2025-12-01"));
// to find results completed between period, not ok
// taskInstanceQuery.taskCompletedAfter(DateUtils.parseDate("2025-11-28"));
// .taskCompletedBefore(DateUtils.parseDate("2025-12-01"));
return taskInstanceQuery.list();
}
However, it didn’t return tasks created (started) between 2025-11-28 and 2025-12-01 as expected; instead, it just returned all tasks (included the deleted tasks, so taskWithoutDeleteReason also didn’t work). taskCompletedAfter and taskCompletedBeforehas the same problem.
Then I tried setting one of taskCompletedAfter, taskCompletedBefore, taskCreatedAfter, or taskCreatedBefore individually, and they all worked as expected on their own. However, combining them produced results that i cant understand.
But for the similar logic (i.e. find the object started or completed during target time range), I can set date range condition successfully on historyService.createHistoricProcessInstanceQuery() and taskService.createTaskQuery(), for example:
// it works as expected
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
historicProcessInstanceQuery.startedAfter(query.getBeginStartTime());
.startedBefore(query.getEndStartTime());
// it works as expected
TaskQuery taskQuery = taskService.createTaskQuery();
taskQuery.taskCreatedAfter(DateUtils.parseDate("2025-11-28"));
.taskCreatedBefore(DateUtils.parseDate("2025-12-01"));
Why is this happening? Did I go wrong?
Thanks in advance. ![]()