Variable updating in the database but not in the process outcome

Dear Camunda Community,

I’m trying to implement an external NodeJS job worker using zeebe-client-node-js. Everything seems to work and I am having no errors in my code but somehow the ‘orderStatus’ variable is not updating when a job is completed and I log process outcome. The ‘orderStatus’ variable is updated into the database but the ‘orderStatus’ variable inside the process outcome is not updating. Any ideas what I’m doing wrong?

The variable is updated inside my database:

The variable is not updated in the Process outcome:

Here is the code:

const customerOrderStatusRejected = zbc.createWorker({
  taskType: 'customerOrderStatusRejected',
  taskHandler: handler,
  debug: true,
  loglevel: 'INFO',
  onReady: () => customerOrderStatusRejected.log('Job worker started successfully!')
});

function handler(job) {
	customerOrderStatusRejected.log('Task variables', job.variables)
    try {
        const updatedProperty = parseInt(job.variables.updatedProperty)
        var connection = mysql.createConnection({
            host: process.env.MYSQL_HOST_NAME,
            user: process.env.MYSQL_USER,
            password: process.env.MYSQL_PASSWORD,
            database: process.env.MYSQL_DATABASE,
            port: process.env.MYSQL_HOST_PORT,
        });
        connection.connect();
        connection.query('UPDATE `customer_order` SET `orderStatus` = "ORDER_REJECTED" WHERE `customer_order`.`id` = ' + updatedProperty + ';',
          async function (error, results, fields) {
            if (error) throw error;
            console.log('Results: ', JSON.stringify(results));
          });
        connection.end();
      } catch (error) {
        console.log(error)
      }
      const updateToBrokerVariables = {
		updatedProperty: 'newValue',
	}
	return job.complete(updateToBrokerVariables)
}
  module.exports = customerOrderStatusRejected;

Any help shall be highly appreciated. Thank you in advance! :smiley:

Kind regards,
Rahib B.

Hi @Rahib_Butt - your job worker isn’t returning the value of ORDER_REJECTED, it is only inserting it into your MySQL database. You need to return the value back to Camunda. You are returning { updatedProperty: 'newValue' } to Camunda, when you should probably be returning { orderStatus: 'ORDER_REJECTED' } instead.

1 Like

Hi @nathan.loding,

The solution you provided surely solved my problem nice and easily.

Thank you for making Camunda community great. More power to you! :smiley:

Regards,
Rahib B.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.