How to initialize a date of a business variable
I'm using the last version of the Community version (7.11.0).
I have a business variable including a DATE ONLY field.
I want to initialize the date with the value of December 31th 2019.
So, when I created my pool variable from a Business Object, I added a script in the "default value" field.
I tried many ways but the process execution always generates an error.
The last script I used :
def formatDate = new SimpleDateFormat()
def myDate = formatDate.parse("yyyy-MM-dd","2019-12-31")
And the error is :
org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: groovy.lang.MissingMethodException: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.lang.String, java.lang.String) values: [yyyy-MM-dd, 2019-12-31]\
I've also tried the following, but in vain :
def myDate = Date.parse("yyyy-MM-dd","2019-12-31")
def myDate = LocalDate.parse("yyyy-MM-dd","2019-12-31")
Thank you in advance for your help.
Hi, from the error message, it seems that you cannot use SimpleDateFormat.parse() with two strings. From the javadoc (https://docs.oracle.com/javase/10/docs/api/java/text/SimpleDateFormat.ht...(java.lang.String,java.text.ParsePosition)) it seems that it requires a string for the date as the first parameter and a Parse Position.
Since you are passing two String parameters, I'm having a hard time understanding your use case. What are you trying to do exactly? Pass a date and a date format and get the date in that format as a result? Or something else?
Hello, as written in the fisrt lines of my message : I want to initialize a DATE ONLY field of a business variable with the value 31/12/2019.
Thank you very much, it works
The final script is :
def myDateString = '2019-12-31'
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate myDate = LocalDate.parse( myDateString, formatter);