Add or subtract days from variable in date timer definition

Hi,

in my process the user enters a date to start an instance - stored in variable “startDate”. I’d like to send a reminder message on the day before that entered day. Unfortunately, I cannot get it running using a timer definition like “${startDate - 1}” or “${dateTime(startDate) - 1}”. I suppose this is a common scenario, so I assume that I just miss something? How would I properly solve this?

My current “solution” is to define an output variable like “remindDate” on a task before, but in my eyes this is more of a workaround than a solution.

Thanks!
Matt

Hi,
I’m not sure of my answer but I see that camunda is using joda-time for the dates.

so I think you can use this :
joda-time

this page of doc https://docs.camunda.org/manual/7.4/user-guide/process-engine/expression-language/#internal-context-functions seems to confirm that

Hope I’ve help.
Romain

Hi Romain,

thanks - I tried this already, but looking into the joda-time docs again, I stumbled over the parse-method. Although it is static, I can call the method on the dateTime()-instance like so:

${dateTime().parse(startDate).minusDays(1).toDate()}

Maybe not the finest solution, but it works.

Thanks!

Hi again,

unfortunately, the approach above does only work, when the variable type of startDate is string. Therefore, I cannot be satisfied with it. However, all of the things I tried do not work out. I cannot believe that this simple and omniscient problem is not solvable easily. Please note, that I use the REST-API only and cannot program on the engine side.

Can anyone help me?

Thanks,
Matt

Hi Matt,

Ive attached a sample which should be close to what you want. The start form creates a date variable. I then use some groovy script in an input mapping to create the reminder date for the timer boundary event.

regards

Rob
Dynamic_Timer.bpmn (7.7 KB)

2 Likes

Hi Rob,

thank you, this seems to be working fine. I still don’t like it not being a single-line statement, but it at least implements RFC1925. :slight_smile:

Greetings,
Matt

Hi Matt.

You can do it in a one-liner:

#{ dateTime().withMillis( someJavaUtilDate.getTime() ).minusDays(2).toDate() }

But I agree that this is a bit ugly and hard to figure out. Maybe you want to create an issue for that to introduce a new function like

dateTime( someJavaUtilDate )

Cheers
Bernd

2 Likes