How can I complete a task using the Java API? A mocked up example would be helpfull.
Hi @withnoe,
You can use the TaskService to complete a task by its taskId. Have a look at the docs:
https://docs.camunda.org/manual/7.14/reference/bpmn20/tasks/user-task/#completion
Best, McAlm
Thanks! I am new to Java so this may be incorrect. Below is what I have tried and am getting errors.
No signature of method: org.camunda.bpm.engine.impl.ProcessEngineImpl.call() is applicable for argument types: () values: []
def varNames = runtimeService.getVariables(it.executionId)
String requestId = varNames.requestId
String pidm = varNames.pidm
String taskId = âa76bb7f7-1220-11eb-b309-0800271e8913â
if (requestId != null && pidm != null) {
def advisorApprovalCheck = approvalMySqlService.advisorApprovalCheck(requestId, pidm)
if(advisorApprovalCheck != null) {
def advisorComplete = processEngine()
.setVariable (âadvisorApprovalâ, advisorApprovalCheck.advisorDecision)
.complete(taskId)
}
}
Hi @withnoe
Can you take a look at the Style Guide? Itâll help you understand how to format code correctly and also help you create questions that are easy to understand and also easier to answer
Hi @withnoe,
Where did you put that code? It is not valid Java codeâŚLooks like Groovy. Did you put it into a script Task or a Listener? The service calls are wrong, youâll need to get the needed services from the processEngine first, e.g. the RuntimeService to update a variable, the TaskService to complete a UserTask.
Probably it helps if you have a closer look to our docs describing how scripting works:
Best, McAlm