Unexpected variables returned after user task


I am facing an odd situation. This is my simplified workflow:

I am first setting a variable “payload” and then start a user task. After completing the user task, when I access the same variable “payload” I am getting some unexpected result when printing the variable in “Get Variable” script task:

{nodeType=OBJECT, number=false, value=false, string=false, object=true, dataFormatName=application/json, boolean=false, array=false, null=false}

If I remove the user task from between, then the variable prints correctly: {"sample":"samvar"}

Edit: This is happening only when I am storing variables as SPIN object

sample.bpmn (4.0 KB)

Hi @armaan6651,

how did you implement the user interaction?

Cheers, Ingo

Hi @Ingo_Richtsmeier

I have just created a user task. There is an external service which checks for pending user tasks and assigns users accordingly.

Hi @armaan6651,

there is no service out of the box. But with the help of a task query, it should be easy to implement one by yourself tailored to your specific needs.

Another option to achive automatic assignment are the new timeout events on user task, released in Camunda 7.12: https://docs.camunda.org/manual/7.12/user-guide/process-engine/delegation-code/#task-listener-event-lifecycle.

Hope this helps, Ingo

Thanks @Ingo_Richtsmeier

I think my question is not very clearly put. My issue is not with the user task. The issue is that, say:

  1. I store a variable X that has value Y in the “Set Variable” script task. This value Y is stored as a SPIN object using execution.setVarable…
  2. There is a user task in between. And a user completes this task
  3. Now when I try to read and print the variable X in the “Get Variable” script task. I get {nodeType=OBJECT, number=false, value=false, string=false, object=true, dataFormatName=application/json, boolean=false, array=false, null=false} instead of Y

This issue happens only when the data is stored as a SPIN object and is fetched after a user task. For eg. if I remove the user task from the sample WF then I get the correct value Y in “Get Variable” script task

Hi @armaan6651,

oh, sorry for the misunderstanding.

The conversion of the variable is done in your user task. What do you/Which API you call to complete it?

How is the user task implemented in your user interface?

Cheers, Ingo

This is the API I am using https://docs.camunda.org/manual/latest/reference/rest/task/post-complete

Hi @armaan6651,

what is the payload of the POST request?

Cheers, Ingo

There is no payload. User will not be sending any data. He will just complete the task.

Hi @armaan6651,

May you please post the scripts for both script tasks “Set Variable” and “Get Variable”…

@hassang This is the payload for Set Variable:

var payload = { "sample":"samvar"}; print("Payload is" + JSON.stringify(payload)); execution.setVariable("payload", S(JSON.stringify(payload)));

Get Variable:
var payload = execution.getVariable("payload"); print(payload);

Also attached is the sample workflowsample.bpmn (4.0 KB)

Hi @armaan6651,

In the Get Variable script, you are trying to print the SpinJsonNode object itself.

I think you should try to print the string representation of it.