User task timer boundary event based on expression set in user task listener

I have a user task in a process model. This user task has a non-interrupting boundary timer event and it uses a Date expression in ISO 8601 format. Can this expression point to a process variable that only gets set in a task listener associated to the user task that has this timer boundary event attached to it? I assume so. Can you confirm or infirm, please?


Thank you, Stephen. I was aware one can use process variables in expressions. My questions was rather related to timing of evaluation. What is the answer to my question: is it yes or no? That is the question :slight_smile:

Looks like the answer is no.

TimerExpressionExample.bpmn (5.5 KB)

Also tried as a Task listener. And also tried to set the variable as part of process Start and then overwrite the variable on task start, but same error.

Thanks for your effort Stephen. That was not my question. You are trying to set the expression from timer event listener. I was proposing to set in from user task “create” event (the user task to which timer boundary event is attached). I expect it to work.

From start process it will work beyond any doubt. I don’t know why it failed when you tried.

@Cristian, well when you solve it, would be interested for you to share some sample code/bpmn.

Yes, Sir! :slight_smile: I will do it.

just FYI, that is what my sample BPMN does. On the User Task Execution Event: Start, the variable is set.
There is no expression or script that runs on the actual timer.

Ok, then I misunderstood. Thanks, Stephen.

just double checked the code, and there was a error. Was using the wrong type of Cron expression.

TimerExpressionExample.bpmn (5.6 KB)

Updated file with fixed cron expression. But still getting a failure. If i place the cron expression directly in the timer definition field, it works as expected. Use a expression that uses a variable that is defined with JS in the User Task execution listener Event Type: Start, and it fails.

JS in Start Event for Execution listener of User Task: execution.setVariable("timerCycle","0 0/1 * * * ?");

Timer Definition: ${timerCycle}

@Cristian if you have done this before, please share. Very interested to see solution as have many use cases that this would apply to.

edit: though there seems to be another problem where dozens of timer instances are being executed rather than 1 ever minute… will have to investigate another day :smile:

Okay fixed using

definition that gives expected result is: 0 0/1 * 1/1 * ? *.

If someone can explain the functional difference between

  • 0 0/1 * 1/1 * ? * and
  • 0 0/1 * * * ?

That would be great.

Okay @Cristian i did some more testing. I think there is a bug or something special about when a Timer’s definition gets evaluated. It seems like the definition is evaluated before Execution Listener Start is executed for the user task.

If you take the following:

execution.setVariable("timerValue", "0 0/1 * 1/1 * ? *");

And run it in a Execution listener in the Sequence flow right before the user task, there are no problems. If you run it in a script task before the user task, no problems. If you define it at process start, there are no problems. But if you try and set the variable in the Execution Listener for the Start Event in the User Task that the Timer is attached to, the variable is not updated in time, and the timer definition appears to be evaluated before the variable is set.

This seems to conflict with the docs of when the Start event for a Execution Listener is fired (unless there is some docs tucked away that i missed :slight_smile: always possible.) The docs currently indicate:

When an execution arrives in the activity to which the boundary event is attached, a timer is started.

@Cristian do you have a working example of this? or were you assuming it should function based on how executions listeners function based on docs?

@camunda could you provide some insight?

Hi Cristian and Stephen,

you can’t use a task listener because it is invoked after the user task is created. You can found the description in the docs:

create: occurs when the task has been created and all task properties are set.

Note that creating the timer boundary event is a part of the task creation.

Best regards,

1 Like

Doesn’t a Start execution listener occur before task create event?
@Philipp_Ossler the error was occurring when using the execution listener.

@StephenOTT, no the timer event is created before.

@Philipp_Ossler why is this the case? Is this the case for all boundary events? (task and sub-process)? Just from a “plain english” explanation: Start and End Execution Events occur before the “Create” and Complete event of a task. If the Task is not created, then why is a event that is related to the Task being evaluated before the task is created?

For your reference to the docs about the Task Listener Create event, it makes complete sense that you could not set the variable of the timer. but Execution listener Start event is occurring before the “Create” event.

I will update the docs with the explanation, as it would be a very good bit of information to have :slight_smile:

@Stephen and Philipp: I guess the other option to model this case is to add an event subprocess which is part of a subprocess having the user task only. Something like:

In this case, if ‘do stuff’ user task doesn’t complete within 5 days of its creation, a reminder will be sent to potential assignees or current assignee. The expression used in non-interrupting event for event subprocess is computed by an expression based on ‘now’ plus 5 days.

@Philipp : I assume this will work in Camunda.

@Cristian, for the use case you mentioned in your first post, you could add the execution listener to the Sequence Flow that connects to the user task, and it works as expected without issue.

1 Like

@Stephen: thanks, I had that temptation as well, but did not try it. I prefer this idea combined with usage of boundary event, rather than subprocess approach. It is simpler and cleaner. Thanks!