Setting a task due date using javascript task listeners

Hi,

I was trying to use a create task listener in javascript to set the task due date. But no matter what type I feed to task.due, the result is always null:

I tried both the javascript date object and ISO formatted string:

task.due = new Date();
task.due = ‘2018-05-29T04:17:35.369Z’
task.due = ‘2018-05-29T04:17:35.0+0800’

The last format works fine with the REST API. But none of the above works in task listener.

Is it possible to set the task due date in this way? I had no problem in the past with setting task.name but that was simple string. What format shall use to correctly set the task.due?

Hi @Yuan_HOng,

Inside the script of task listener, the variable task is available, which corresponds to the DelegateTask interface.

And based on camunda docs dueDate should be used (Not due)
try task.dueDate instead of task.due

https://docs.camunda.org/javadoc/camunda-bpm-platform/7.7/org/camunda/bpm/engine/delegate/DelegateTask.html#setDueDate(java.util.Date)

Thanks @hassang,

task.dueDate is the correct interface. I was misled by the differing REST API parameter name for changing task due date. But now another problem arises:

What format of date shall I assign to task.dueDate? According to doc it shall be a java.util.Date object. But how can I create such an object from javascript?

I have tried:

task.dueDate = new Date();
task.dueDate = ‘2018-05-29T04:17:35.369Z’
task.dueDate = ‘2018-05-29T04:17:35.0+0800’
task.dueDate = java.util.Date();
task.dueDate = 1527583922.500724;

And all failed with either of the following errors:

Cannot cast java.lang.String to java.util.Date
Cannot cast jdk.nashorn.internal.objects.NativeDate to java.util.Date
Unable to evaluate script: TypeError: java.util.Date is not a function
cannot convert MethodHandle(TaskEntity,Date)void to (Object,int)void

Did you try

task.dueDate = new java.util.Date();

1 Like

@hassang

That works, thank you!!