About in the event:'onAfterAutoSchedule' to get task data which is pre value problem, need help!


Here is my question:
There are two tasks has a link like A -> B , and i set task B a new start_date and new end_date, My function is call back end a API to calculate a new timezone then to set task B new value, when i get the new data from back end and set task B new value(the new value is absolute follow the link’s rule).

But !!! in the event: ‘onAfterAutoSchedule’, I have a function in it, to use the updateIds to getTasks and call API to update tasks data which is been update by AutoSchedule. In here, I use gantt.getTask() function, but now I get pre value of task B !!???

At first, I think maybe is the event: ‘onAfterAutoSchedule’ is called before I get new data form backend and set new data for taskB, but i use debugger findout is not !!! I set new data’s for task B is before the event: ‘onAfterAutoSchedule’ , why in the event, i use gantt.getTask() is get pre value ??

here is my code:

  1. get backend’s data to set new data and updateTask()
    const newData = rs.content;
    if (!!newData && newData.length > 0) {
    newData.forEach(i => {
    const singleTask = this.gantt.getTask(i.id);
    singleTask.start_date = new Date(i.start_date);
    singleTask.end_date = new Date(i.end_date);
    singleTask.duration = i.duration;
    singleTask.workFlow = i.workFlow;
    singleTask.principal = i.principal;
    singleTask.owningUsers = i.owningUsers;
    singleTask.milestone = i.milestone;
    singleTask.manHour = i.manHour;
    if (this.gantt.getChildren(singleTask.id).length > 0 && !singleTask.milestone) {
    singleTask.type = this.gantt.config.types.project;
    } else {
    singleTask.type = singleTask.milestone ? this.gantt.config.types.milestone : this.gantt.config.types.task;
    this.gantt.updateTask(i.id, singleTask);

  2. use Ids in that event,to call gantt.getTask()
    this.gantt.attachEvent(‘onAfterAutoSchedule’, (taskId, updatedTasks) => {
    console.log(‘taskId: %o, updatedTasks: %o’, taskId, updatedTasks);
    if (taskId) {
    updatedTasks = […updatedTasks];
    const dates = this.extractDates(updatedTasks);
    if (dates.length > 0) {
    this.updateTaskDates(this.project.id, dates);
    return true;
    }, null);

private extractDates(taskIds): any {

const result: {
taskId: string | number,
startDate: Date,
finishDate: Date,
duration: string | number,
constraintType: string,
constraintDate: Date
}[] = taskIds.map(item => {
const task = this.gantt.getTask(item); (problem in here, get pre value)
let constraintType = this.constraintTypeForSelect.find(item => item.id === task.constraint_type)?.key;
if (!constraintType) {
constraintType = this.constraintTypeForSelect.find(item => item.id === this.gantt.config.constraint_types.ASAP)?.key;

const children = this.gantt.getChildren(task.id);
if (children.length > 0) {
return {
taskId: task.id,
startDate: this.gantt.getSubtaskDates(task.id).start_date,
finishDate: this.gantt.getSubtaskDates(task.id).end_date,
duration: this.gantt.getSubtaskDuration(task.id),
constraintDate: task.constraint_date
} else {
return {
taskId: task.id,
startDate: task.start_date,
finishDate: task.end_date,
duration: task.duration,
constraintDate: task.constraint_date
return result;


I couldn’t reproduce the issue in the following snippet:
If I drag task #2, I see the updated start_date of Task #3 in the dev tools.

Probably, the issue is related to the Gantt configuration, but it is hard to suggest what might be wrong as I don’t see your code.

Please, add all your Gantt configuration in the following snippet and make sure that the issue is reproduced there:
Then, click on the Share button and send me the link.
Or send me a ready demo with all the necessary Javascript and CSS files so that I can reproduce the issue locally.


Actually, I just reproduce the problem in your link: http://snippet.dhtmlx.com/5/11102dd35

Here is the steps:

  1. edit Task #3 's start_date to 11 April , the task did’t update it’s start_date,which is still in the 06 April
  2. I drag the Task #3 and it update it’s date, then I drag it to start_date in 06 April
  3. After 1 and 2, I retry the step 1, now it’s start_date can jump to 11 April !!??

I don’t know what’s different between edit the data and drag the task , but the ‘onAfterAutoSchedule’ give me a different thing


Thank you for giving the steps to reproduce the issue.
If you initially modify the task from the lightbox, you don’t change the constraint type. As the task still has the ASAP constraint, it is rescheduled to an earlier date. So, you get the date after a task was auto-scheduled.
After you drag a task, you set its constraint to SNET, and that allows you to modify the constraint date, so the task is not rescheduled to an earlier date. There are no updated tasks in the onAfterAutoSchedule event, so, you won’t see any dates in the web console after steps 2 and 3.

It will work the same way in the following snippet, but now, the constraints are visualized:

To make it even more clear, here is the snippet, where Gantt doesn’t auto-schedule tasks:
You will need to click on the button after the tasks are loaded, then update the task date from the lightbox. After you click on the button, the task will be rescheduled to an earlier date, and the event handler will return the start_date after Gantt finished auto-scheduling the task.


thanks for answer the question