How to modify process variable (camunda-external-task-client-js)?

I want to modify process variable in external task client
I could get process variables but could not modify.

When I call variables.setTypes() or variables.set() function,
there’s type error which says set (or setTyped) is not a function

I found when task executed, variables are constructed with readonly: true options
(https://github.com/camunda/camunda-external-task-client-js/blob/6429f7d684df9be37c89cb4013120230fae8ba3b/lib/Client.js#L307)

and because of that, Variable does not have set* functions
(https://github.com/camunda/camunda-external-task-client-js/blob/6429f7d684df9be37c89cb4013120230fae8ba3b/lib/Variables.js#L77)

Am I right?

Do you have any idea to modify process variables?
Is the only way call rest API directly?


test code (typescript)

const output: CamSDK.TypedValue = task.variables.getTyped(‘output’);
try {
output.value[0].videoOptions = ‘modified options…’;
task.variables.set(‘output’, output);
taskService.complete(task);
} catch (err) {
console.error(err);
}


console output

[ { file: ‘abc.mxf’, options: ‘-pix_fmt vvvv’ },
{ file: ‘123.mxf’, options: ‘-pix_fmt aaaa’ } ]
TypeError: task.variables.set is not a function

Hi @hados,

a common pattern is create a new Variables object and pass the result from your service here to the task.

Have a look at this example: https://github.com/camunda/camunda-external-task-client-js/blob/6429f7d684df9be37c89cb4013120230fae8ba3b/examples/granting-loans/index.js#L36-L53

Hope this helps, Ingo