Get form key from historic task

2019-08-10 01:01发布

问题:

We get the form key from task service likes following snipped code

for (Task task : getTaskService().createTaskQuery().taskCandidateGroupIn(candidateGroup).initializeFormKeys().list()) {

task.getFormKey()
....
....
...

}

but now for some special reason we wanna get the form key value from HistoricTaskInstance, and we try several ways to get it but all of them fail.

We are wondering that how we can get the form key value from completed task?

回答1:

The form key is not available for historic tasks. Usually forms are not displayed for historic tasks since the tasks have been completed. If the task has not been completed (history contains both active and completed tasks), then you can use the id of the historic task to get the form key using the form service.

If the task has already been completed, then you need to use the model api to get the form key from the XML:

HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().singleResult();

BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(historicTask.getProcessDefinitionId());

org.camunda.bpm.model.bpmn.instance.Task task = bpmnModelInstance.getModelElementById(historicTask.getTaskDefinitionKey());
String formKey = task.getAttributeValueNs(BpmnModelConstants.CAMUNDA_NS, "formKey");


标签: camunda