Hi,
I am new on Camunda (and enjoy it a lot so far).
I am trying to transfer information from a Javascript application to a workflow, via an external task.
In Javascript, the service task sets a variable this way:
In the service task, an output parameters is set up as:
person <- ${person}
So that the process variable person is set to the person object (btw, when I do complete(task, variables), hoping, that the person process variable is set, it does not work. It seems this is due to the fact that person already exists as a process variable, before the task is executed, but I donât understand why it is not allowed to override a process variable that way).
In a following task, I would like to set an input parameter as follows:
personId = ${person.id}
but this does not work: the service task appears as still running, even though it has been executed, and is retried (re-executed) periodically.
Do you know how to access the person ID properly?
A workaround I have tried is to have an intermediate script task (Javascript) as follows:
var c = S(person)
var personId = c.prop("id")
execution.setVariable("personId", personId)
But I find this overly complex for a âbusinessâ process.
What is the null parameter supposed to be? I am not very good with Javascript but at least the Java api does not contain taskService.complete with three different parameters.
In Java you would need to do this with taskService.complete(task, variables)
it looks like an external task cannot modify a process variable from JavaScript, if this process variable was already existing in the process. (but it works if I set a new process variable, though. And it also works if I assign a process variable from a local variable, in the Output Parameters settings in the modeler)
it looks like accessing a process variable field (like person.id) from a task following an external service task, causes the service task not to complete.
I am sorry, I cannot send the workflow for now.
I have checked the various cockpit panels/tabs, but could not see any issue. About the logs, do you mean there is a log file? Where can it be found (I am running the provided docker container installation)
Thanks, but itâs not in the javascript task that I need to access the ID, but in the task which follows in the workflow. And I need to output the full âpersonâ out from the javascript task.
Hi again,
So I could investigate further thanks to your recommendations.
See the attached workflow.
Here is the Javascript code used for the âCreateContactâ external service task:
let processVariables = new Variables();
processVariables.set('instanceOut', { firstname: 'a', lastname: 'b', id: 123})
let ret = await taskService.complete(task, processVariables)
In the âSend Emailâ task, I then try to access ${instanceOut.id} to set an input variable. But I get this error in the logs:
[nio-8080-exec-5] org.camunda.bpm.engine.rest.exception : ENGINE-REST-HTTP500 org.camunda.bpm.engine.ProcessEngineException: Unknown property used in expression: ${instanceOut.id}. Cause: Could not find property id in class org.camunda.spin.impl.json.jackson.JacksonJsonNode
As you may check in the BPMN file, I try to access the ID with the expression ${instanceOut.id}
It looks like this cannot work, but do you know how to access the id attribute of the instanceOut object?
And I now have another issue, which confirms what I was assuming in my initial message: an external task seems to not be able to update a process variables if it was already existing.
In the attached diagram, I now try to acces the instance process variable from the SendEmail task.
In the JavaScript code of the external service task, I have renamed instanceOut to instance:
let processVariables = new Variables();
processVariables.set('instanceOut', { firstname: 'a', lastname: 'b', id: 123})
let ret = await taskService.complete(task, processVariables)
And then I get this error:
[nio-8080-exec-7] org.camunda.bpm.engine.rest.exception : ENGINE-REST-HTTP500 org.camunda.bpm.engine.ProcessEngineException: Error while evaluating expression: ${S(instance).prop(âidâ)}. Cause: org.camunda.spin.json.SpinJsonPropertyException: SPIN/JACKSON-JSON-01004 Unable to find âidâ
Please note that the âUser createâ event is triggered by a signal, which provides an instance variable to the process, but which has no id attribute. In the process instance panel of the cockpit, I can see 2 rows for the instance variable. They are both of type Json, but one has the process scope âCreateContactFromSignalâ, and the other one the âCreate Contactâ task scope.
So, do you see why the instance process variable cannot be modified by the Javascript service task?
All process variables are handled as a map in the process engine. If you provide a new value to an existing key (variable name), the old value will be overwritten. Do you see any exceptions from the external task worker or in the engine log?