Can't manipulate Process Variables from javascript (node) when following Niall's tutorial for distributed

I’m following along with Niall (and his hawk) here and doing the “Roman invasion” demo for Camunda in a Distributed System.

I can’t actually create or manipulate the process variables in my javascript. I constantly get log errors saying:

:heavy_multiplication_x: couldn’t complete task XYZ, Unknown property used in expression: #{not north}. Cause: Cannot resolve identifier ‘north’

Exactly as in the video, I start with:

const { Variables } = require(“camunda-external-task-client-js”);

And my logic:

// subscribe to the topic: ‘DecideOnExpansion’
client.subscribe(“DecideOnExpansion”, async function({ task, taskService }) {

// Put your business logic
var flipcoin = Math.random() >= 0.5;
console.log("Variable flipcoin is set to ", flipcoin)

const processVariables = new Variables();
processVariables.set("north", flipcoin);

// complete the task
await taskService.complete(task);

When I run my .js with node, I’m subscribed, and I can see my task handler being called but there’s no effect on the process variables when I call .set() and I get the error above.

What am I missing?

You just need to change the complete method to

await taskService.complete(task, processVariables);

that will add the variables to the complete call.
You can see more in the docs

Ah, thanks so much for the fast reply! I knew I was missing something fundamental. Makes perfect sense.

1 Like