@Override
protected Void execute(CommandContext commandContext, TaskEntity task) {
FormService formService = CommandContextUtil.getFormService(commandContext);
if (formService == null) {
throw new FlowableIllegalArgumentException("Form engine is not initialized");
}
FormRepositoryService formRepositoryService = CommandContextUtil.getFormRepositoryService(commandContext);
FormInfo formInfo = formRepositoryService.getFormModelById(formDefinitionId);
if (formInfo != null) {
Map<String, Object> formVariables = formService.getVariablesFromFormSubmission(formInfo, variables, outcome);
if (task.getProcessInstanceId() != null) {
formService.saveFormInstance(formVariables, formInfo, task.getId(), task.getProcessInstanceId(),
task.getProcessDefinitionId(), task.getTenantId());
} else if (task.getScopeId() != null) {
formService.saveFormInstanceWithScopeId(formVariables, formInfo, task.getId(), task.getScopeId(), task.getScopeType(),
task.getScopeDefinitionId(), task.getTenantId());
}
FormFieldHandler formFieldHandler = CommandContextUtil.getCmmnEngineConfiguration(commandContext).getFormFieldHandler();
formFieldHandler.handleFormFieldsOnSubmit(formInfo, task.getId(), null, task.getScopeId(),
task.getScopeType(), variables, task.getTenantId());
completeTask(commandContext, task, formVariables);
} else {
completeTask(commandContext, task, variables);
}
return null;
}