To provide context, I’m trying to play with the process instance migration API and I’m following along with this example:
https://blog.flowable.org/2019/08/07/migration-of-a-bpmn-process/
I’m running Flowable 6.4 (so it’s possible the feature doesn’t exist fully yet?)
On to the problem at hand. I have a workflow diagram that has a subprocess, First Review Cycle. In there is a single user task, First Approval. After First Review Cycle ends, the workflow continues on to another user task in the main workflow, Second Task. I started by spinning up an instance of this basic workflow. Then I modified the workflow to add a value for the category and description fields of First Approval. I migrated the process instances based upon my code snippet (which I will include below). While the migration did not throw any errors, I could not get Category or Description to update on the migrated task instance, despite the task now reporting that it belonged to a newer version of the workflow.
Moving on from that, I added a new variable to the process instance variables in the workflow definition, migrateData. I tried to again perform the workflow migration, this time attempting to use the example above to forcibly update the new process instance variable. I got an exception that the function withProcessInstanceVariable could not be found. Here’s the code I’m using to do this (it’s written in ColdFusion, in case you wonder why the syntax looks funky. Should translate pretty easily to Java code once the variable declaration and loop syntax are changed over to Java). I’ve also included a picture of what my BPMN diagram looks like. If the entire BPMN is needed, let me know.
var repositoryService = processEngine.getRepositoryService();
// Get the latest process definition we just deployed
var processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("migrationTest").latestVersion().singleResult();
// Get all running process instances for our existing process
var runtimeService = processEngine.getRuntimeService();
var processInstancesList = runtimeService.createProcessInstanceQuery().processDefinitionKey("migrationTest").includeProcessVariables().list();
result = getProcessesAsObjectArray(processInstancesList);
// Now walk that list and execute the migration routine for each running process
for (process in processInstancesList) {
// Works for basic happy path of adding a new step to the workflow
//runtimeService.createProcessInstanceMigrationBuilder().migrateToProcessDefinition(processDefinition.getId()).migrate(process.getId());
// Works kind of -- Lets me add a new step to the workflow or change the activity ID of an existing step, but doesn't let me see updates to task category or description values on running process instances
// runtimeService.createProcessInstanceMigrationBuilder().migrateToProcessDefinition(processDefinition.getId())
// .addActivityMigrationMapping("step1", "approvalStep1")
// .migrate(process.getId());
// Dies horribly on the attempt to update the new process instance variable, migrateData
runtimeService.createProcessInstanceMigrationBuilder().migrateToProcessDefinition(processDefinition.getId())
.withProcessInstanceVariable("migrateData", "This was set by migration function")
.addActivityMigrationMapping("step1", "approvalStep1")
.migrate(process.getId());
}