Hi,
Is there a way to add variables from a job worker back into the workflow via the job worker?
For example, I tried this, but it doesn’t work:
List orderedOptions = orderedOptionsClass.getOptions();
job.getVariablesAsMap().put(“orderedOptions”, orderedOptions);
Thanks,
Ken
Hey @ken
you can complete a job with variables, see in this example https://docs.zeebe.io/clients/java-client-examples/data-pojo.html the last line of the handler.
Greets
Chris
Hi Chris,
(@Zelldon)
I appreciate the response.
I tried your solution. I might be doing something wrong, but so far I don’t see what. (I do this kind of stuff very often with Camunda.) The variables passed in when starting the workflow instance, but not the ones passed in from the job. I use the Spring/Java client.
@ZeebeWorker(type = "get-ordered-options"):
public void handleGetOrderedOptionsJob(final JobClient client, final ActivatedJob job) {
try {
logJob(job);
client.newCompleteCommand(job.getKey()).send().join();
Map<String, Object> variablesMap = job.getVariablesAsMap();
String orderId = (String) variablesMap.get("orderId");
...
Map<String, Object> map = new HashMap<>();
map.put("orderedOptions", orderedOptions);
client.newCompleteCommand(job.getKey()).variables(map).send();
...
}
next job worker
@ZeebeWorker(type = "set-option-values-in-request")
public void handleSetOptionValuesInRequestJob(final JobClient client, final ActivatedJob job) {
try {
logJob(job);
client.newCompleteCommand(job.getKey()).send().join();
...
Map<String, Object> variablesMap = job.getVariablesAsMap();
List<Option> orderedOptions = (List) variablesMap.get("orderedOptions");
}
This job recognizes before even starting that the “orderedOptions” variable it is not there. orderedOptions is an input collection on a multiinstance subprocess. I am running the jobs inside the intelliJ debugger. (Won’t be able to get back to this until Monday.)
Ken
Hi Chris,
(@Zelldon)
Never mind. I figured out what the problem is. Beginner’s mistake.
I had an extra newCompleteCommand statement earlier, too early.
client.newCompleteCommand(job.getKey()).send().join();
and later this.
client.newCompleteCommand(job.getKey()).variables(map).send();
1 Like