Adding custom column value to links table

Good day everyone

I got an issue:

I wanna link my tasks and links to specific projects, so I add project_id to tasks table and it’s working with this:

gantt.attachEvent(“onTaskCreated”, function(task){
task.project_id = <?php echo $project->id ?>;
return true;
});
with Links I try with this: (not working)

gantt.attachEvent("onBeforeLinkAdd", function(id,link){
link.project_id = <?php echo $project->id ?>;
return true;
});

The links appear on the gantt chart but they are not saved on the database.

Any ideas :slight_smile: ?

Thanks

Hello,
Could you share some of your backend code and some basic info, such as what libraries you use, do you see any errors coming from a backend when you create links, etc. ?

I might be looking for something similar: I would like to extend the link object with more data when calling ‘onAfterLinkAdd’. The gantt chart I’m trying to create is generated from multiple DB tables and to link dependencies, I need to determine what table the ‘task’ is in and what table the ‘dependency’ is in.

The multiple tables is due to project/task tables and also a maintenance table that all scheduled maintenances get created in. These maintenances can be assigned to a project and tasks can be dependent on their successful completion, sort of like a milestone, I guess.

My code for the ‘onAfterLinkAdd’ is:

        gantt.attachEvent("onAfterLinkAdd", function(id, link){
            if (link['type'] != "0") {
                toastr['warning']("This link type is not allowed at this time.", "Link Fail")
                gantt.deleteLink(link['id'])
            } else {
                post_data = {}
                post_data['dependency'] = link['source']
                post_data["project_id"] = {{project.id}}
                post_data['task'] = link['target']
                $.post('<url>', post_data, function(data){
                    toastr[data.type](data.message, data.title) //alerting system
                })
            }
        });

I would like to add ‘db_type’ to the ‘post_data’ but even in the received json I get when I build the gantt chart, the added fields aren’t added to the div’s.

Any help would be most appreciated. Thanks!

Hello,
Thank you for giving us details.
I forwarded your message to the dev team. They will try to look into your question soon.

Hello,
In case if you need help with the use case, you can try using the Ajax module:
https://docs.dhtmlx.com/gantt/api__gantt_ajax_other.html

Here is the code you can use:

gantt.attachEvent("onAfterLinkAdd", function(id, link){
  if (link['type'] != "0") {
    //toastr['warning']("This link type is not allowed at this time.", "Link Fail")
    gantt.deleteLink(link['id'])
  } else {
    post_data = {}
    post_data['dependency'] = link['source']
    post_data["project_id"] = '{project.id}'
    post_data['task'] = link['target']
    gantt.ajax.post({
      url:"server.php", 
      data: {
        url: '<url>',
        db_type: "linkDB",
        paramName: "paramValue"
      }
    }).then(function(response){
      var res = JSON.parse(response.responseText); 
      if (res && res.status == "ok") {
        // response is ok
      }
    });
  }
});

After adding a link, you will see the request in the Network tab in the web console:

Here is the snippet:
http://snippet.dhtmlx.com/827197153