Problems with updating task

Hi,

I’m currently trying to update my Tasks.
Now when i’m initializing the gantt chart, i need to format my start_date into the “dd-mm-yyyy” format. When i try to update a task with a start date of the same format, i always get “invalid day index”. I’ve also tried passing a javascript Date object, which worked (for whatever reason).

Now the next problem occurs when i try to update a duration. So what i do is:

var task = gantt.getTask(id); task.duration = 50; gantt.updateTask(id);

But the duration does not change, period. Do I need to manually calculate the new end_date and set it as well?

Thanks and Regards

Hi,
you need to use JS Dates when you change start/end dates of the task objects on the client side. The stringified dates are only supported in gantt.parse and gantt.load methods.

Regarding start_date/end_date/duration values - yes, the dependent values should be recalculated manually:var task = gantt.getTask(id); task.duration = 50; task.end_date = gantt.calculateEndDate(task.start_date, task.duration); gantt.updateTask(id);
docs.dhtmlx.com/gantt/api__gantt … ddate.html

Ok, so now i have this code. To make sure i’m using input values, i just set all values to dummy values.

record.start_date = new Date(2015, 1, 1);
record.duration = 10;
var end_date = gantt.calculateEndDate(record.start_date, record.duration, "day");

var task = gantt.getTask(record.text);
	if (task) {
		console.log("start_date: " + record.start_date + " end_date: " +
 	gantt.calculateEndDate(record.start_date, record.duration, "day")	
							+ " duration:" + record.duration);

	task.duration = record.duration;
	task.start_date = record.start__date;
	task.end_date = gantt.updateTask(record.text);
}

And it logs:

start_date: Sun Feb 01 2015 00:00:00 GMT+0100 (W. Europe Standard Time) end_date: Sat Feb 14 2015 00:00:00 GMT+0100 (W. Europe Standard Time) duration:10 

And ultimately, i still get the “invalid day index” errors.

check the last line task.end_date = gantt.updateTask(record.text);
updateTask does not return a value, so after this line you get task.end_date === undefined
Also, what is the record.text value? You use it as an id of the related task, is it correct?
docs.dhtmlx.com/gantt/api__gantt_updatetask.html

Sorry, i actually managed to screw up the code in the example from copy and pasting around.

record.text is a string and used as the id.
since gantt.getTask(record.text) does return the actual task, i assume that it works.

[code] record.start_date = new Date(2015, 1, 1);
record.duration = 10;
var end_date = gantt.calculateEndDate(record.start_date, record.duration, “day”);

					var task = gantt.getTask(record.text);
					if (task)
					{
						console.log("start_date: " + record.start_date + " end_date: " + gantt.calculateEndDate(record.start_date, record.duration, "day")
								+ " duration:" + record.duration);

						task.duration = record.duration;
						task.start_date = record.start__date;
						task.end_date = end_date;
						gantt.updateTask(record.text);
						gantt.render();
					}[/code]