Currently I’m using Zeebe NodeJS client for implementing job workers. I am having an issue of not receiving any process variables from the previous pool.
I believe I need to publish a message which I’m doing already from the previous pool and then receive it in the next pool, there I should be able to receive the variables using “Message start event” with the same “message name” that I published from “Send production order”. Here is the code for “Send production order” worker:
const { ZBClient, Duration } = require('zeebe-node')
const uuid = require('uuid');
const sendCustomerOrderForProduction = new ZBClient();
sendCustomerOrderForProduction.publishMessage({
correlationKey: 'quantity',
messageId: uuid.v4(),
name: 'juststart',
variables: { valueToAddToProcessVariables: 'here', status: 'PROCESSED' },
timeToLive: Duration.seconds.of(10), // seconds
})
sendCustomerOrderForProduction.createWorker({
taskType: 'sendCustomerOrderForProduction',
taskHandler: handler,
})
function handler(job) {
console.log('Task variables', job.variables)
console.log("Sending customer order now for production...");
console.log("Number of bicycles to be produced: ", job.variables.quantityNeededForProduction);
// Task worker business logic goes here
const updateToBrokerVariables = {
updatedProperty: 'newValue',
}
return job.complete(updateToBrokerVariables)
}
module.exports = sendCustomerOrderForProduction;
Since each pool is a distinct process, you are not expected to be able to retrieve process variables from a different process.
Your message contains the variables “valueToAddToProcessVariables” and “status”, which you can see are being set in the new process. If you need other variables, then you would need to pass them as part of the message.
Thank you for your reply. Could you please share an example how can I do that? I have been trying to do it for hours but sadly no progress.
So let’s say I want job.variables.quantityNeededForProduction variable to pass as part of the message, how can I achieve that please?
How can I access the variable in the sendCustomerOrderForProduction.publishMessage({}) object after the job has been completed by the worker sendCustomerOrderForProduction.createWorker({}) object?
Well, answering to my own thread after spending days in figuring out a way of sending process instance from one pool to another pool using “Send Task” with all the previous process variables. Thought it might help someone trying to implement something similar , here is the solution:
const { ZBClient, Duration } = require('zeebe-node');
const zbc = new ZBClient();
const uuid = require('uuid');
//Declare all your process variables globally here that you are using
let quantityNeededForProduction = ''; //example process variable from the pool you are sending the process from
const messagePayload = {
messageId: uuid.v4(),
name: 'receiveProductionOrder', //Global message reference of "Message Start Event" inside Camunda Modeler
variables: {
// Include any other variables that you want to pass to the workflow
},
timeToLive: Duration.seconds.of(10), // seconds
};
const sendCustomerOrderForProduction = zbc.createWorker({
taskType: 'sendCustomerOrderForProduction',
taskHandler: handler,
onReady: () => sendCustomerOrderForProduction.log('Job worker started successfully!')
});
function handler(job) {
quantityNeededForProduction = job.variables.quantityNeededForProduction;
console.log("\nNumber of bicycles to be produced: ", job.variables.quantityNeededForProduction);
// Task worker business logic goes here
updateToBrokerVariables = {
quantityNeededForProduction: quantityNeededForProduction,
};
// Include the updated variables in the message payload for the next step in the workflow
const updatedMessagePayload = {
...messagePayload,
variables: {
...messagePayload.variables,
...updateToBrokerVariables,
},
};
// Publish the updated message to the workflow
zbc.publishMessage(updatedMessagePayload);
// Complete the current job
job.complete(updateToBrokerVariables);
console.log("\nSending customer order for production: ", updatedMessagePayload)
}
module.exports = sendCustomerOrderForProduction;
You appear to have a bug in this, in that you are providing a variables block in both the Job JSON template (messagePayload) and in the “Message to Send” block (updatedMessagePayload)
As you discovered (which is what was advised in the prior post) - the solution is to pass the variables from the initiating process to the destination process within the message.