Process instance migration from Java

Hi All,

I have to migrate the process instances from previous process definition to latest one without using the cockpit. can I write java code to perform this operation, if yes can anyone provide sample code or guide how to implement the same.

Hi @syedkp. This might be a helpful read: Process Instance Migration | docs.camunda.org

1 Like

Thanks @lzgabel . Let me review the link and come back if any questions.

Hi @lzgabel . I tried using the link you shared below. But I think there are few incidents and those need to be migrated as well. Can you help me how to migrate the incidents. Below is the error message and code.

Failed to migrate instances :
org.camunda.bpm.engine.migration.MigratingProcessInstanceValidationException: ENGINE-23004 Cannot migrate process instance ‘c29ad55b-38e0-11ed-bff0-3441
5d90ed8c’:
Cannot migrate transition instance ‘c29ad55b-38e0-11ed-bff0-34415d90ed8c’:
There is no migration instruction for this instance’s activity

public void migrateInflightInstances(String sourcePDId, String targetPDId){
MigrationPlan migrationPlan = runtimeService
.createMigrationPlan(sourcePDId,targetPDId)
.mapEqualActivities()
.build();

    ProcessInstanceQuery processInstanceQuery = runtimeService
            .createProcessInstanceQuery()
            .processDefinitionId(migrationPlan.getSourceProcessDefinitionId());

    runtimeService.newMigration(migrationPlan).processInstanceQuery(processInstanceQuery).execute();
}

Hi @syedkp.
The reason for the error is that the corresponding migration instruction cannot be created by calling the mapEqualActivities method. It is because the corresponding mapping cannot be found in your newly deployed model.

For example:

Version-1:

Version-2:

:warning: When the corresponding mapping cannot be found automatically in the two models, please use the mapActivities method to manually specify.

MigrationPlan migrationPlan = runtimeService.createMigrationPlan(sourceId, targetId)
                .mapActivities("user-task-id", "manual-task-id")
                .build();

ProcessInstanceQuery processInstanceQuery = runtimeService
                .createProcessInstanceQuery()
                .processDefinitionId(migrationPlan.getSourceProcessDefinitionId());

runtimeService.newMigration(migrationPlan).processInstanceQuery(processInstanceQuery).execute();

@lzgabel - Thanks for the response. I havent changed anything within the modeler. As I mentioned above, I am getting error that incidents havent migrated. We are using embedded camunda version and dont have cockpit available. so I have to write java code for migration. Can you tell me how to migrate incidents? Also all incidents are failedJob.

did you achive this ? could you please share yiur experience