Search code examples
javacamundabusiness-process-management

How get the latest process definition of camunda irrespective of a process instance


I'm trying to get the latest process definition to perform various operations irrespective of any specific process. I also wanted to migrate my existing processes to the latest definition. Can someone guide me for the same? Docs are not of much help.


Solution

  • You can query deployed process definitions using the RepositoryService (assuming you are using the java api):

    repositoryService.createProcessDefinitionQuery()
        .latestVersion()
        .processDefinitionKey("myProcess")
        .singleResult();
    

    For process instance migration, you can create and execute MigrationPlans:

    MigrationPlan migrationPlan = processEngine.getRuntimeService()
       .createMigrationPlan("exampleProcess:1", "exampleProcess:2")
       .mapActivities("assessCreditWorthiness", "assessCreditWorthiness")
       .mapActivities("validateAddress", "validatePostalAddress")
       .mapActivities("archiveApplication", "archiveApplication")
       .build();
    

    as documented here. There is also a community extension for instance migration , which is a bit outdated, but at least should give you some ideas how to work with the API.