Change business variable field when a user takes a task

Hi.

I've got an instantiation form, that when submitted, creates a human task for a role (let's say approvers) that contains 2-3 members. Any of those members are able to take the task.

My question is, when somebody takes a task, is there a way for me to update a "Status" field in my business variable that reflects this change ?

For e.g.:
Person A takes the task --> "Status" field in my business variable changes to "Reviewing".
If Person A releases the task back for somebody else to take it --> "Status" field in my business variable changes to "Open".

Any way I can do this ? Maybe using an API or by other means ?

 

Hello,

You both are correct. BDM is supposed to be updated only on an operation.

But, thanks to Bonita, there is still a way! But I would not recommend it.

First, how do you know one task is assigned? You have to possibility.

1/ by a Cron. You run this job every 10 mn, checking the assigned task, then update your BDM (see below). I would recommend creating a new job in Truckmilk (https://community.bonitasoft.com/project/pagetruckmilk-execute-jobs-intervalle) to do that (then you already have all the infrastructure, administration...).

2/ via the Event Handler mechanism (https://documentation.bonitasoft.com/bonita/7.11/event-handlers) . You register on the event "assigned" and you can do what you want. Attention, using the event handler:

* you have to configure the server 

* the event handler is then called for every assigned task, whatever the process

* you are at the bottom of the engine. A transaction on the engine database is then already opened, maybe a transaction on the BDM database too, you have to check

* you are in a critical section for the engine. That's means, if your code is long, it can block all the Bonita Engine

* according to the event handler strategy, if you throw an exception, the operation is canceled. So, pay attention to catch all your exception and to not throw then if you don't want to abort the transaction (or if you want to abort the assignment, this is the way)

Saying that the event handler is a great mechanism.

---------------------------------

So, how could you update the BDM?

In the Bonita spirit, only an operation can update the BDM. That the reason why you don't have any API to update a BDM variable?. Saying that, the Bonita Engine has some internal API (attention, you are "behind the miror" here : theses API may be not stable between version). have a look to the MoonRover page (https://community.bonitasoft.com/project/pagenoonrover-access-your-bdm-and-query-it) , this page update existing BDM variable with the API (and this page does not works after 7.10, something change and we hae to review this part ;-0  ).

Second, BDM is a database, you can try to update it in SQL via JDBC. Get the Datasource via the BonitaProperties library (https://community.bonitasoft.com/project/bonita-properties).

Attention then: this is definitively not recommended, and not supported. Secondly, pay attention to release properly the BDM connection, because the Bonita Engine uses it. Then, the Bonita Engine and Hibernate may use caches: you change directly via SQL will not update any cache.

This is a lot of information, sorry about that, hope this helps

 

Hello

I also have a similar problem.
From what I understand, BDM can be updated from Operation section. Hence Taking a Task will not update the BDM.
You can try using a connector but connectors are executed as soon as the Task is initiated. Assiging the task or Unassigning the task has no effect as connector is already fired.
Hence in conclusion its not possible to Update BDM from API or any other way except Operations.

P.S - Please let us know if you have found a solution.

Regards

Nope. I haven't found a solution either to this.

Hi Dibyajit.Roy

Just a little precision regarding connector execution: you can put connectors on entering the task (task initialization, as you mention), but also on finishing the task (that is, when you execute the task for a Human task, or when it completes for an Automatic task).

I had to rectify that.

I hope that is clearer now.

Regards