Invalid argument task object Object of gantt.isUnscheduledTask

Hi,

I’m trying to use dhtmlx JavaScript libraries for using the gantt functionality as a JavaScript control add-in in Business Central.
I’m getting the project and tasks loaded, but there are messages diplayed at the right part of the screen telling my Invalid argument task=[object Object] of gantt.isUnscheduledTask. Task object was expected.

Altough all my tasks have a start and end date, there seem to be an issue and I’m not able to find were it is.
Below my sample json:

{
    "data": [
        {
            "id": 1,
            "open": true,
            "parent": 0,
            "progress": 0,
            "text": "Installation of S-100 Semi-Automatic",
            "type": "project"
        },
        {
            "id": 2,
            "parent": 1,
            "progress": 0,
            "text": "Phase 1 - Planning and specs",
            "type": "project"
        },
        {
            "end_date": "2024-03-05",
            "id": 3,
            "parent": 2,
            "progress": 1.0,
            "start_date": "2024-03-03",
            "text": "Pre-installation requirements"
        },
        {
            "id": 5,
            "parent": 1,
            "progress": 0,
            "text": "Phase 2 - Installation",
            "type": "project"
        },
        {
            "end_date": "2024-03-06",
            "id": 6,
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-06",
            "text": "Delivery"
        },
        {
            "end_date": "2024-03-12",
            "id": 7,
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-07",
            "text": "Installation"
        },
        {
            "end_date": "2024-03-14",
            "id": 8,
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-13",
            "text": "Configuration"
        }
    ]
}

For anyone that might face this issue in the future, stingify jour json object before parsing

var tasks = JSON.stringify(data);
gantt.parse(tasks);

Hello Job,
I couldn’t reproduce the issue with the dataset you shared:
https://snippet.dhtmlx.com/yq0he6t8

When you use the parse method, it is not necessary to use the JSON data. You can also use the Javascript object:
https://snippet.dhtmlx.com/6pd2zqyp

If you want, you can share a test JSON object that you use, and I will check if there is something wrong with it or you just need to properly configure Gantt.

Hi Ramil,

Thank you for lookin in to this.
I don’t think there is something wrong with the dataset (see below the json before sending to the gantt).
Business Central has the behavior of turning my json in a JavaScript Object when sending to the control add-in.

This is how the object looks like before parsing:

When I don’t use the stringify before gantt.parse… then I get the errors

{
    "data": [
        {
            "id": 1,
            "open": true,
            "parent": 0,
            "text": "Installation of S-100 Semi-Automatic",
            "type": "project"
        },
        {
            "end_date": "2024-03-08",
            "id": 2,
            "label": "Job Task: FIX RATE JOB,100",
            "parent": 1,
            "start_date": "2024-03-04",
            "text": "Phase 1 - Planning and specs",
            "type": "project"
        },
        {
            "end_date": "2024-03-08",
            "id": 3,
            "label": "Job Task: FIX RATE JOB,110",
            "parent": 2,
            "progress": 1.0,
            "start_date": "2024-03-04",
            "text": "Pre-installation requirements"
        },
        {
            "end_date": "2024-03-23",
            "id": 5,
            "label": "Job Task: FIX RATE JOB,200",
            "parent": 1,
            "start_date": "2024-03-22",
            "text": "Phase 2 - Installation",
            "type": "project"
        },
        {
            "end_date": "2024-03-09",
            "id": 6,
            "label": "Job Task: FIX RATE JOB,220",
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-08",
            "text": "Delivery"
        },
        {
            "end_date": "2024-03-13",
            "id": 7,
            "label": "Job Task: FIX RATE JOB,240",
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-11",
            "text": "Installation"
        },
        {
            "end_date": "2024-03-16",
            "id": 8,
            "label": "Job Task: FIX RATE JOB,260",
            "parent": 5,
            "progress": 1.0,
            "start_date": "2024-03-13",
            "text": "Configuration"
        }
    ],
    "links": [
        {
            "color": "blue",
            "id": 1,
            "source": 3,
            "target": 6,
            "type": "0"
        },
        {
            "color": "blue",
            "id": 2,
            "source": 6,
            "target": 7,
            "type": "0"
        },
        {
            "color": "blue",
            "id": 3,
            "source": 7,
            "target": 8,
            "type": "0"
        }
    ]
}

Hello Job,
I tried to reproduce the issue in the following snippets, but it seems to be working correctly:
https://snippet.dhtmlx.com/jxl3goes
https://snippet.dhtmlx.com/0b5n34q6

So, maybe there is something wrong with the Gantt configuration. If you want to investigate the issue further, you can add your configuration to the following snippet and make sure that the issue is reproduced there:

Then, click on the Save 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.

Hi @ramil ,

I added my configuration (DHTMLX Snippet Tool) but everything seems to work ok in this snippet tool.
For me there is no further investigation needed as I found a workaround.

Regards,
Job

Hello Job,
Thank you for sharing the configuration. I don’t see anything wrong that might cause the issue. So, maybe something wrong happens when Business Central parses the data and does something with it.
However, I see that you add the scale configuration via the gantt.conig.scales parameter and the Zoom extension. This is not an expected way to do that. You need to use the gantt.conig.scales parameter or the Zoom extension:
https://docs.dhtmlx.com/gantt/desktop__zooming.html

Right now, there are no issues, but if you try using both approaches simultaneously, you may get unexpected behavior.