Update task with auto reschedule

I can’t understand why the following snippet is not working:

http://snippet.dhtmlx.com/5/2d9583712

try to click on addTasks then addLink then updateTask.

What I would expect to see (and what I want to achieve) is that clicking in this manner will create the tasks, put the link with the relevant lag (that works until here) than updating the first task date should move the second task (or all the tasks that are linked to that task) backwards one day (to match the link lag and because autoschedule is on)

Hello Refael,
There are several things you need to change in the snippet to make it work.
If you are passing the task object in the updateTask method, you need to include all the necessary parameters as Gantt would expect them. There are mandatory parameters: start_date, end_date, duration. Without them, the task won’t be correctly updated.
There are also additional task properties that related to links:
$source and $target. Even if a task doesn’t have links, it should have these properties:

It should work correctly without these properties, but the auto-scheduling feature expects tasks to have links or at least these properties.

Also, you pass the date in a string format. You need to manually convert it to the Date object.

If you do only that, the task will be moved to a new position:
http://snippet.dhtmlx.com/5/6cab60695
But as the link IDs are not listed in the $source and $target parameters, they are not repainted. In that case, Gantt will reflect the changes only after the next repainting.
So, you need to include the link IDs there, then everything will work as expected:
http://snippet.dhtmlx.com/5/644e7a1f2

Thanks for the detailed response Ramil, whats the command to repaint the Gantt? Also, in the second link you have sent the task is updated as expected but the lag is turning to be 2 instead of 1 (when what I want is for task 2 to move 1 day so that the lag won’t change). I expected that to work like that because auto-schedule is on.

Hello Refael,

whats the command to repaint the Gantt?

You can use the gantt.render or gantt.refreshData methods to do that:
https://docs.dhtmlx.com/gantt/api__gantt_render.html
https://docs.dhtmlx.com/gantt/api__gantt_refreshdata.html


Also, in the second link you have sent the task is updated as expected but the lag is turning to be 2 instead of 1 (when what I want is for task 2 to move 1 day so that the lag won’t change). I expected that to work like that because auto-schedule is on.

It will work like that after the next auto-scheduling occurs. When you drag a task in the timeline or change its dates in the lightbox, Gantt auto-schedules tasks after applying the changes. If you use API methods, Gantt doesn’t do that.
Here is the updated snippet with the gantt.autoSchedule method:
http://snippet.dhtmlx.com/5/76907c211