Easily control the freezing and unfreezing of approval processes: making work smoother
About 465 wordsAbout 2 minDecember 2, 2024
1. Retrieve Current Process Instance Information
When implementing the freeze and unfreeze functionality, the first step is to obtain the information of the current process instance. You can get this information using the process instance ID:
TaskService taskService = processEngine.getTaskService();
Task currentTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
String currentTaskId = currentTask.getId();
2.1. Freeze Process Instance
Freezing a process instance typically involves suspending the current task and updating the process instance status:
RuntimeService runtimeService = processEngine.getRuntimeService();
runtimeService.suspendProcessInstanceById(processInstanceId);
System.out.println("Process instance has been frozen: " + processInstanceId);
2.2. Unfreeze Process Instance
Unfreezing a process instance requires reactivating the suspended process instance:
runtimeService.activateProcessInstanceById(processInstanceId);
System.out.println("Process instance has been unfrozen: " + processInstanceId);
3. Update Database Tables
After completing the freeze and unfreeze operations, you need to update the relevant records in the database to ensure data consistency. Assuming we have created the following database tables:
- Process_Instances: Stores information about process instances
- Approval_Tasks: Stores information about approval tasks
- Approval_Logs: Stores logs of approval actions
Update the status in the process instances table:
-- Freeze process instance
UPDATE Process_Instances
SET Status = 'FROZEN', Updated_At = NOW()
WHERE Process_Instance_ID = ?;
-- Unfreeze process instance
UPDATE Process_Instances
SET Status = 'ACTIVE', Updated_At = NOW()
WHERE Process_Instance_ID = ?;
If needed, you can also update the task status in the approval tasks table:
-- Freeze approval task
UPDATE Approval_Tasks
SET Status = 'FROZEN', Completed_At = NOW()
WHERE Process_Instance_ID = ? AND Task_ID = ?;
-- Unfreeze approval task
UPDATE Approval_Tasks
SET Status = 'ACTIVE', Completed_At = NULL
WHERE Process_Instance_ID = ? AND Task_ID = ?;
Log the freeze and unfreeze actions:
-- Log freeze action
INSERT INTO Approval_Logs (Task_ID, Approver_ID, Action, Timestamp, Comments)
VALUES (?, ?, 'FROZEN', NOW(), 'Task has been frozen');
-- Log unfreeze action
INSERT INTO Approval_Logs (Task_ID, Approver_ID, Action, Timestamp, Comments)
VALUES (?, ?, 'ACTIVATED', NOW(), 'Task has been unfrozen');