Add time period to input date in DMN Table

Hi All

I saw this post from almost 2 years ago but there was no solution so I was wondering if we couldn’t figure it out: DMN Date Arithmetic

I would like to compare an input date in a dmn table e.g date1 to a second date after it has had a period of time added to it.

I.e. date1<date2+6months

I managed to achieve this by first calculating “date2+6months” and storing it in a new variable called “date3” in a script task using groovy as follows:

import org.joda.time.DateTime
def date3 = new DateTime(date2).plusMonths(6).toDate()

and then doing the comparison “date1 < date3”

However I want to be able to do away with the script task and then do it directly in a DMN table something as follows:

What expression would I need to put into the Input Conditions to achieve this. I.e replace <date2+6months with what?

Thanks so much in advance to anyone who is willing to help.

Hi @kdgeyser,

one option is to write a JUEL or Groovy expression in the input entry which uses the dateTime(...) function.

Another way is to use the FEEL extension. Using the extension, you can write something like: date1 < date2 + duration("P6M") (as FEEL expression).

Does this help you?

Best regards,
Philipp

Hi Philipp

Thanks so much for the response. I managed to get it to work using the first option.
However with the second option I couldnt get the FEEL extension to work as i kept getting errors as in this post (seems with no solution?): https://github.com/camunda/feel-scala/issues/21.

But thanks so much I really appreciate it

Hi @kdgeyser,

it’s nice to hear that it works :slight_smile:

Anyways, it should also work with the FEEL extension since the bug #21 is solved with version 1.4.0. See the wiki for details. Assuming that the variable date1 is a date-time then you should set the type to feel-date-time or feel-local-date-time.

Best regards,
Philipp

I see. I think the issue is that I enabled the extension on our server which is running camunda but not onto my local machine and hence I didnt get the options in the modeler of setting the date type to “feel-date-time or feel-local-date-time.” But I will enable it on both and try again

With regards to the previous solution:

I managed to get it to work by changing the Expression Language to Groovy and then using the expression: DateTime(date1).plusDays(180)

However I have subsequently decided I want to keep the Expression Language as Juel but when I put the expression “DateTime(date1).plusDays(180)” in the “Expression” input block in camunda I get the error “DMN-01002 Unable to evaluate expression for language ‘juel’: ‘${DateTime(date1).plusDays(180)}’”

How can I fix this i.e. what do I need to put in the Expression Input Box?
Also what is the “Input Variable Name” field used for?

Really appreciate all the help.
Kind Regards

Hi @kdgeyser,

I think that you must use the fully qualified name of DateTime. You can try this: ‘${org.jode.date.DateTime(date1).plusDays(180)}’.
If the variable date1 is already a date-time then you can write ${date1.plusDays(180)}.

Please have a look at the docs for input variable name.

Regarding

The option is not there but you can just write the type by hand.

Best regards,
Philipp