# REST batch process instance migrate with variables

**URL:** <https://forum.flowable.org/t/rest-batch-process-instance-migrate-with-variables/8067>\
**Category:** Flowable Engine\
**Created:** [June 30, 2021, 1:17pm UTC](https://forum.flowable.org/t/rest-batch-process-instance-migrate-with-variables/8067 "2021-06-30T13:17:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubends](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@rubends](https://forum.flowable.org/u/rubends)\
**Post date:** [June 30, 2021, 1:17pm UTC](https://forum.flowable.org/t/rest-batch-process-instance-migrate-with-variables/8067/1 "2021-06-30T13:17:52Z")

</div>

Hi

We are migrating all process instances of a process definition by using the process definition migrate REST call. However, we would also like to update / edit / add / remove some variables of said instances.  
We found the following POST body as a solution:

```auto
{
	"toProcessDefinitionId": "process:2:id",
	"activityMappings": [
		{
			"fromActivityId": "sid-1",
			"toActivityId": "sid-2"
		}
	],
  "processInstanceVariables":
	{
			"name" : "value"
	}
}

```

Does anybody know a way if it is possible to conditionally edit these variables, to see which value they already have in a certain activity of a running process before we would change them with the migration?  
This is so that new process definitions don’t have to take into account that some values could be different from a previous process definition.

I find almost no documentation about these migration REST calls and their response are pretty empty when succeeded.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![martin.grofcik](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/martin.grofcik/32/71_2.png) [@martin.grofcik](https://forum.flowable.org/u/martin.grofcik)\
**Post date:** [June 30, 2021, 2:32pm UTC](https://forum.flowable.org/t/rest-batch-process-instance-migrate-with-variables/8067/2 "2021-06-30T14:32:47Z")

</div>

Hi rubends,

`org.flowable.engine.migration.ProcessInstanceMigrationDocumentConverter#convertFromJson` converts the json from the request to `ProcessInstanceMigrationDocument` you can add any pre/post upgradeScripts to your migration doc.  
example:

```auto
...
"preUpgradeScript": {
    "language": "groovy",
    "script": "1+1"
  },
  "postUpgradeScript": {
    "language": "groovy",
    "script": "2+2"
  },
...

```

change variable type:

```auto
        processMigrationService.createProcessInstanceMigrationBuilder().preUpgradeScript(new Script("groovy",
                "import com.fasterxml.jackson.databind.ObjectMapper\n"
                        + "import com.fasterxml.jackson.databind.node.ArrayNode\n"
                        + "import org.flowable.engine.impl.context.Context\n"
                        + "\n"
                        + "List<String> list = execution.getVariable('listVariable')\n"
                        + "\n"
                        + "ObjectMapper mapper = Context.getProcessEngineConfiguration().getObjectMapper()\n"
                        + "\n"
                        + "ArrayNode jsonArray = mapper.createArrayNode()\n"
                        + "list.each {jsonArray.add(it)}\n"
                        + "\n"
                        + "execution.setVariable(\"listVariable\", jsonArray)"))
                .migrateToProcessDefinition(targetProcessDefinition.getId())
                .migrate(processInstanceToMigrate.getId());

```

Regards  
Martin
