AnsweredAssumed Answered

ScriptTask + TimerBoundaryEvent

Question asked by soma on Jan 15, 2014
Latest reply on Jan 16, 2014 by soma

I have a simple Activiti diagram with a ScriptTask and a TimerBoundaryEvent.
You can see my diagram if you open this url:

My first task is a ScriptEvent task. In this task (I use JavaScript) I would like to set a date variable. It represents the start time of the process. After ScriptEvent task I have some other tasks and a TimerCatchingEvent component. It is a TimerIntermediateCatchEvent. Here I want to reuse my predefined variable and set it as a timeDate property of my TimerCatchingEvent component.

Here is my script of the ScriptEvent task:

<scriptTask id="scripttask1" name="Set timer variable" scriptFormat="javascript" activiti:autoStoreVariables="true">
//var now = new Date();

// 5 minutes later
execution.setVariable("process_start_time", new Date((new Date()).getTime() + 5 * 60000) + "");

// 2 months later
//execution.setVariable("process_start_time", today + 60);</script>

My TimerCatchingEvent definition:

<intermediateCatchEvent id="timerintermediatecatchevent1" name="TimerCatchEvent">

If I use Date type in my ScriptTask I get this persist exception: Couldn't serialize value '' in variable 'process_start_time'

In order to avoid serialization exception I convert the Date type to String with a litle trick: +"". It works fine.

But now I have another exceprion: couldn't resolve duedate: Invalid format: "Wed Jan 15 2014 14:33:48 GMT+010…". So my date format is not align to the expectation.

My questions are:
* How can I set a Date type variable with ScriptEvent task? If I use Date type I get a serializable exeption.
* How can I set dinamically the value of the timeDate parameter of TimerCatchingEvent component via ScriptEvent task.

If possible I would like to avoid to use java class for this easy function.