You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The handler function is used to handle a fetched task.
const{ Client, logger, Variables }=require("camunda-external-task-client-js");// create a Client instance with custom configurationconstclient=newClient({baseUrl: "http://localhost:8080/engine-rest",use: logger});// create a handler functionconsthandler=asyncfunction({ task, taskService }){// get the process variable 'score'constscore=Variables.get("score");// set a process variable 'winning'constprocessVariables=newVariables().set("winning",score>5);// set a local variable 'winningDate'constlocalVariables=newVariables().set("winningDate",newDate());// complete the taskawaittaskService.complete(task,processVariables,localVariables);};// susbscribe to the topic: 'topicName'client.subscribe("topicName",handler);
task.variables
The variables object is a read-only Variables instance.
It provides various getters
for reading the process variables in the scope of the service task.
client.subscribe("bar",asyncfunction({ task, taskService }){// output all process variablesconsole.log(task.variables.getAll());});
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Put your business logic// Complete the taskawaittaskService.complete(task);});
taskService.handleFailure(task, options)
Parameter
Description
Type
Required
task
task or id of the task to handle failure.
object or string
✓
options
options about the failure.
object
options include:
Option
Description
Type
Required
Default
errorMessage
An message indicating the reason of the failure.
string
errorDetails
A detailed error description.
string
retries
A number of how often the task should be retried. Must be >= 0. If this is 0, an incident is created and the task cannot be fetched anymore unless the retries are increased again. The incident's message is set to the errorMessage parameter.
number
retryTimeout
A timeout in milliseconds before the external task becomes available again for fetching. Must be >= 0.
number
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Put your business logic// Handle a FailureawaittaskService.handleFailure(task,{errorMessage: "some failure message",errorDetails: "some details",retries: 1,retryTimeout: 1000});});
taskService.handleBpmnError(task, errorCode)
Parameter
Description
Type
Required
task
task or id of the task to handle bpmn failure
object or string
✓
errorCode
An error code that indicates the predefined error. Is used to identify the BPMN error handler.
string
✓
errorMessage
An error message that describes the error.
string
variables
Map of variables which will be passed to the execution.
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Put your business logic// Create some variablesconstvariables=newVariables().set('date',newDate());// Handle a BPMN FailureawaittaskService.handleBpmnError(task,"BPMNError_Code","Error message",variables);});
taskService.extendLock(task, newDuration)
Parameter
Description
Type
Required
task
task or id of the task to extend lock duration
object or string
✓
newDuration
An amount of time (in milliseconds). This is the new lock duration starting from the current moment.
number
✓
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Put your business logic// Extend the lock timetry{awaittaskService.extendLock(task,5000);console.log("I extended the lock time successfully!!");}catch(e){console.error(`Failed to extend the lock time, ${e}`);}});
taskService.unlock(task)
Parameter
Description
Type
Required
task
task or id of the task to unlock
object or string
✓
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Put your business logic// Unlock the taskawaittaskService.unlock(task);});
taskService.lock(task, newDuration)
Parameter
Description
Type
Required
task
task or id of the task to extend lock duration
object or string
✓
duration
An amount of time (in milliseconds). This is the lock duration starting from the current moment.
number
✓
// Susbscribe to the topic: 'topicName'client.subscribe("topicName",asyncfunction({ task, taskService }){// Task is locked by default// Put your business logic, unlock the task or let the lock expire// Lock a task againtry{awaittaskService.lock(task,5000);console.log("I locked the task successfully!");}catch(e){console.error(`Failed to lock the task, ${e}`);}});