6

I got a special question regarding timer boundary events on a user task in Activiti/Camunda:

When starting the process I set the timer duration with a process variable and use expressions in the boundary definition to resolve the variable. The boundary event is defined on a user task.

<bpmn2:timerEventDefinition id="_TimerEventDefinition_11">
        <bpmn2:timeDuration xsi:type="bpmn2:tFormalExpression">${hurry}</bpmn2:timeDuration>
      </bpmn2:timerEventDefinition>

In some cases, when the timer is already running it can occur, that the deadline (dueDate) should be extended because the asignee has requested more time. For this purpose i want to change the value of the process variable defining the deadline.

As it happens, the variable is already resolved at the process-start and set to the boundary event.

Any further changes of the variable do not affect the dueDate of the boundary timer because it is stored in the database and is not updated when the value of the variable changes.

I know how to update the dueDate of the job element via the Java API, but i want to provide a generic approach like setting it with changing the value of the variable.

The most common use case for extending the deadline will be when the boundary timer is already running.

Any ideas how to cope with this problem?

Any tips are very apprechiated. Cheers Chris

theFriedC
  • 424
  • 7
  • 20

3 Answers3

3

After some time of thinking I came up with a workaround like that:

enter image description here

I start the process with two variables. "hurry" is evaluated for the boundary timer. And "extendDeadline" is initialized with false. If the timer triggers and the process advances to the exclusive gateway, the value of "extendDeadline" is evaluated.

If a user has changed the value of "extendDeadline" to true during the the timer was running the process returns to the user task again where the boundary timer is set to the value of "hurry".

If the "extendDeadline" is still set to false, the process can proceed.

theFriedC
  • 424
  • 7
  • 20
  • what if new due date is before old due date? – Srinath Ganesh Jun 05 '19 at 09:54
  • @SrinathGanesh - first of all - the old due date still must be reached. then the timer event would trigger again immediately (at latest with the next job worker) because the new due date is in the past. You can exit the potential loop by resetting the extendDeadline variable to false again. Anyway - you could also check if the new date is before the old date and then ignore it because for me there is no point in shortening the due date for this use case. As far as I know there is a Java API for changing timer due dates now. There you could also shorten the due date. – theFriedC Jun 06 '19 at 10:16
2

If the timer is running you can change dueDate of the timer by executing a signal. If a assginee requested more time, set new value of hurry and execute the signal. The old timer will be canceled and the new timer will be created with new due date.

runtimeService.setVariable(execution.getId(), "hurry", newDueDate);
runtimeService.signalEventReceived(signalName, execution.getId());

Process with signal

fersmi
  • 601
  • 3
  • 9
  • 1
    Thank you fersmi for your suggestion. I think "managementService.setJobDuedate(jobId, newDueDate)" would do the trick also. But what I want to achieve is, that the dueDate of the job is updated directly by changing the variable value, without custom code. At the Camunda Cockpit for example, a user can edit the value of variables. This should be enough to extend the dueDate. (At least in my imagination ;) – theFriedC May 12 '15 at 08:00
  • Modifying the job due date was my first idea, too. – Jan Galinski May 12 '15 at 08:25
  • There is a Jira ticket pending at Camunda, introducing variable listeners. This is exactly what I am looking for. Hopefully they will implement it soon ... https://app.camunda.com/jira/browse/CAM-2899 – theFriedC May 12 '15 at 10:02
  • @fersmi: Coming to your suggestion again: How could I send the signal from outside my code? – theFriedC May 12 '15 at 10:06
  • @theFriedC: I am not sure what do you mean outside your code? You can use REST API http://www.activiti.org/userguide/#_rest_api for outside interaction or you can create your own interface. It depends what kind of technologies you use it. – fersmi May 12 '15 at 11:37
  • @fersmi: I just wondered how i could send a signal using some standard tools like the Camunda Cockpit. There I can change the values of variables on running process instances but this tool does not provide the functionality to send a signal. I do not intend to customize the tool so I am looking for a solution that is contained in the process definition – theFriedC May 12 '15 at 14:33
  • Nevertheless: I understand now, what you wanted to show me with your example: The trick is to let the process return to the user task. Then the expression referencing the variable is evaluated again and the job is started with the new dueDate. – theFriedC May 12 '15 at 14:34
0

Solution is to have 2 out going sequence flow, one should be from boundary timer on task and another one should be from task it self, as shown in diagram added by @theFriedC. See following image also.enter image description here

Then you can use some exclusive gateway on 2nd sequence flow and reroute that back to same task with a new timer value.

Alok Anand
  • 3,346
  • 1
  • 20
  • 17