cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to use Date Object in Script Task

caiw
Champ in-the-making
Champ in-the-making
Hi,

When I try to use a Date object (javascript) in a script task I get the following exception:


com.vaadin.event.ListenerMethod$MethodException
Cause: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: coudn't deserialize value 'sun.org.mozilla.javascript.internal.NativeDate@d99967' in variable 'tD'
   at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
   at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
   at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
   at com.vaadin.ui.Button.fireClick(Button.java:539)
   at com.vaadin.ui.Button.changeVariables(Button.java:206)
   at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1299)
   at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1219)
   at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:735)
   at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
   at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:662)
Caused by: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: coudn't deserialize value 'sun.org.mozilla.javascript.internal.NativeDate@d99967' in variable 'tD'
   at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
   at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
   at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
   at org.activiti.explorer.ui.form.FormPropertiesForm.access$000(FormPropertiesForm.java:46)
   at org.activiti.explorer.ui.form.FormPropertiesForm$1.buttonClick(FormPropertiesForm.java:145)
   at sun.reflect.GeneratedMethodAccessor189.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
   … 22 more


This is the javascript code I use (I'm going to set the date according to a process variable later, but first I must be able to create a Date object..):

//set timeDate
var tD = new Date();

Why?

Thanks,
caiw
4 REPLIES 4

frederikherema1
Star Contributor
Star Contributor
Try fully-qualifying the "new Date()" -> "new java.util.Date()", as "new Date()" is a javascript-type…

caiw
Champ in-the-making
Champ in-the-making
Thank you, that worked better!

Now I need to convert the date to ISO-8601 format to use it in a TimerCatchingEvent, as Time date.
In the same script task as before, I tried using:

var timeDate = tD.toISOString();

but got the following exception:

Cause: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: problem evaluating script: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function toISOString. (#41) in  at line number 41
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
at com.vaadin.ui.Button.fireClick(Button.java:539)
at com.vaadin.ui.Button.changeVariables(Button.java:206)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1299)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1219)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:735)
at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: problem evaluating script: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot find function toISOString. (#41) in  at line number 41
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
at org.activiti.explorer.ui.form.FormPropertiesForm.access$000(FormPropertiesForm.java:46)
at org.activiti.explorer.ui.form.FormPropertiesForm$1.buttonClick(FormPropertiesForm.java:145)
at sun.reflect.GeneratedMethodAccessor112.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
… 22 more



I've tried different browsers (that are supposed to support Date.prototype.toISOString) but I get the same exception every time.

Is there another way to convert a date object to ISO-format for use in the TimerCatchingEvent?

Thanks,
caiw

frederikherema1
Star Contributor
Star Contributor
You could write a java-class that does this and instantiate it from JavaScript or alter the ScriptBindings, activiti uses to expose additional java-objects on top of the process-variables that are present now…

frederikherema1
Star Contributor
Star Contributor
And by the way, the Javascript is executed on the server, so it doesn't matter what browser you use to access the Vaadin-app anyway…