Deleting a recent link does not work

If I create a link and try to destroy it right away, I get an error.

It works after reloading the page though. I thought it was an issue with storing and communicating link id from the server, but JSON inspector shows it correctly transmitted.

[EDIT] Exact same problem with tasks, but it shows an error in the upper right corner : Task not found id=1535732531574.

Hello,
It can be related to storing data and communicating with the server. Most likely you use Data Processor if you don’t have a custom solution to communicate Gantt with the server. And this is how it works.
When you create a task or a link, they get the ID related to the current time. Then it sends that information to the server and the server creates a record in the database. The Data processor obtains the ID of the new created record in the database and updates the task ID. So for example you create a task and its ID is 1535732531574, after all actions made by Data Processor the task ID becomes 64. The error “task not found” means that Gantt couldn’t find the task.

Could you clarify if you can reproduce it only right after you created a task? Or you can do it within several seconds later until you refresh the page?
In the latter case you can try to check if the link exists, before deleting it. The following commands will show you the information of the last created link or task:

var all_tasks = gantt.serialize().data
console.log(gantt.getTask(all_tasks[all_tasks.length - 1].id))

var all_links = gantt.serialize().links
console.log(gantt.getLink(all_links[all_links.length - 1].id))

Of course, maybe it happens because of something else. If you can reproduce it in the following snippet:
https://snippet.dhtmlx.com/b3e34d9d5
please click on the “Share” button after it is reproduced and send me the link.

Thanks for the explanation! I use the Data Processor indeed and I guess you’re right in assuming the error is related to IDs. It would explain why editing links/tasks won’t work until refresh (and thus reloading ID from the database).

On the server side, I’m not getting an ID during the POST call:
start_date: 2017-07-01 00:00:00
text: New task
duration: 1
end_date: 2017-07-02 00:00:00
parent: 0

But I do send back the last_insert_id:
{“action”:“inserted”,“tid”:13}

Links and tasks are created in the database correctly, I suppose that’s why it does work after a reload.

I tried running your command but to no avail:
var all_tasks = gantt.serialize().data;
console.log(gantt.getTask(all_tasks[all_tasks.length - 1].id));
VM215:2 Uncaught TypeError: Cannot read property ‘id’ of undefined
at :2:59

I guess it means the new tasks doesn’t really exist.

To try to show you what it looks like, here’s what happens when I click on a new task:

I won’t be able to reproduce it in a snippet since it involves server REST calls.

I might have solved it using this topic : Need help with msg "Task not found id=#" after task created

I changed both responses (tasks and links) to “id” instead of “tid” and it looks like it works. If that’s indeed the case, tutorials might need a small update.

I double checked and it doesn’t solve the issue. There are no longer “task not found” errors, but on the server side, tasks and links IDs are incorrect (update and delete no longer work).

[EDIT] For example:

  • Added “new task”
  • Server created task #20 and answered “{“action”:“inserted”,“id”:20}”
  • Tried to delete task #20 and saw that the delete call was sent using ID “1535986782714”

It seems that the ID isn’t overwritten by server’s reponse.

Tried using the refreshData() function quoted in that same topic :
dp.attachEvent(“onAfterUpdate”, function(id, action, tid, response){
gantt.refreshData();
})

It seems that trick no longer works at all:
Uncaught TypeError: t._getVerticalScrollbar is not a function
at n.t._scroll_state (VM1424 dhtmlxgantt.js:10)
at n.t.getScrollState (VM1424 dhtmlxgantt.js:10)
at n.refreshData (VM1424 dhtmlxgantt.js:10)
at a. (14:101)
at a.i (VM1424 dhtmlxgantt.js:10)
at a.t.callEvent (VM1424 dhtmlxgantt.js:10)
at afterUpdateCallback (VM1424 dhtmlxgantt.js:10)
at afterUpdate (VM1424 dhtmlxgantt.js:10)
at a.e.afterUpdate (VM1424 dhtmlxgantt.js:10)
at n (VM1424 dhtmlxgantt.js:10)

I tried to debug it yesterday evening with a friend and we found out that editing another task seems to make the newly created task “refresh” and its id is finally correct.

Is there a refresh that I could force (as a workaround), or how can I determine why the Data Processor won’t use the JSON return containing the id?

[EDIT] Trying to see gantt’s data at load and it says gantt.getTaskCount(); => 0 even though there are two tasks it pulled from the database.

I created a task (now there are 3 total) and it keeps telling me that task count is 0.

Hello,
Thank you for the clarification. You can try to use the following command and get all task’s parameters from the all_tasks variable instead of telling Gantt to find the task:

var all_tasks = gantt.serialize().data;
console.log(all_tasks[all_tasks.length - 1]);

Please tell me which backend you use and did you configure it only according to our tutorials or you also added something else? I have Ruby on Rails backend and tried to reproduce it there, but it works correctly.

Hello!

I followed every step of https://docs.dhtmlx.com/gantt/desktop__howtostart_php.html except that I’m using something closer to the CodeIgniter framework.

The results of serialize().data:

  • After loading:
    gantt.serialize().data;
    (2) [{…}, {…}]0: {id: “15”, id_projet: “14”, text: “MAJ RTTIF”, start_date: “2019-07-01 00:00:00”, duration: 122, …}1: {id: “11”, id_projet: “14”, text: “Cadrage”, start_date: “2018-06-01 00:00:00”, duration: 122, …}length: 2__proto__:

  • After creating a new task:
    gantt.serialize().data;
    (3) [{…}, {…}, {…}]0: {id: “15”, id_projet: “14”, text: “MAJ RTTIF”, start_date: “2019-07-01 00:00:00”, duration: 122, …}1: {id: “11”, id_projet: “14”, text: “Cadrage”, start_date: “2018-06-01 00:00:00”, duration: 122, …}2: {id: 33, start_date: “2019-07-01 00:00:00”, text: “New task”, duration: 1, end_date: “2019-07-02 00:00:00”, …}length: 3__proto__: Array(0)

It shows that the new task has the right id, but it still displays “Task not found, id:16544235478something”.

I saw that Ids were strings when retrieved and integers when received via JSON so I tried changing that (it didn’t work). “Id_projet” is not used in the gantt representation and is only a value store in the database.

Hello,
Thank you for the clarification.
I tried to reproduce it in the official demo where I connected MySQL database. I can create and delete tasks without issues.
Please send me your package so that I can reproduce it locally.

I will try to send you an URL so that you can test it by yourself. I have some censorship to do beforehand though. Thanks for your help!

I gave up. Issue probably lies in my implementation of the JSON return.