Is there a way to directly right a date value to the Gantt Chart´s “Start Time” and “End Time”? I am looking for something that will work using a process such as:
date string (from popup Calendar component) > parse > data calculation > write to Gantt Chart
I am having issues with the Gantt Chart component. I keep getting an error message when I try to set the Gantt Chart dataset to a built data set. The code is below.
# reads task data from root´s Custom Property 'taskData'
taskData = event.source.parent.taskData
# Builds ganttData dataset with no row data
headers = ['Task Name', 'Start Date', 'End Date', 'Percentage Done']
data =[]
ganttData = system.dataset.toDataSet(headers, data)
# sets percentage and startDate
percentage = 0
startDate = event.source.parent.getComponent('calStartDate').date
rows = taskData.getRowCount()
for row in range(rows):
rowData =[]
taskName = taskData.getValueAt(row,'task_name')
weeks = taskData.getValueAt(row,'task_week')
if row == 0:
startDate = system.date.parse(startDate, "yyyy-MM-dd HH:mm:ss")
endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")
else:
prevEndDate = system.date.parse(ganttData.getValueAt(row-1,'End Date'), "yyyy-MM-dd HH:mm:ss")
startDate = system.date.parse(system.date.addDays(prevEndDate, 1), "yyyy-MM-dd HH:mm:ss")
endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")
rowData.append(taskName)
rowData.append(startDate)
rowData.append(endDate)
rowData.append(percentage)
ganttData = system.dataset.addRow(ganttData, rowData)
#system.db.runPrepUpdate("INSERT INTO temp_timelines (taskName, startDate, endDate, percentage) VALUES (?,?,?,?)", [taskName, startDate, endDate, percentage])
#chartData = system.db.runQuery("SELECT taskName AS 'Task Name', startDate AS 'Start Date', endDate AS 'End Date', percentage AS 'Percentage' FROM temp_timelines")
event.source.parent.getComponent('Gantt Chart').data = ganttData
I have tried many different ways to parse the string - python and Java methods, but I admit to being a rookie so I could have easily overlooked some detail.
Having said that, I explored another method that did work, but via a circuitous route. I first INSERT the row data into to a MySQL table with DATETIME columns and then SELECT this data assigning it to the Gantt Chart table property. While this process works I do not like it as I am trying to reduce DB transactions when possible.
system.db.runPrepUpdate("DELETE FROM temp_timelines WHERE taskName LIKE ?", ['%'])
# reads task data from root´s Custom Property 'taskData'
taskData = event.source.parent.taskData
# Builds ganttData dataset with no row data
headers = ['Task Name', 'Start Date', 'End Date', 'Percentage Done']
data =[]
ganttData = system.dataset.toDataSet(headers, data)
# sets percentage and startDate
percentage = 0
startDate = event.source.parent.getComponent('calStartDate').date
rows = taskData.getRowCount()
for row in range(rows):
rowData =[]
taskName = taskData.getValueAt(row,'task_name')
weeks = taskData.getValueAt(row,'task_week')
if row == 0:
startDate = system.date.parse(startDate, "yyyy-MM-dd HH:mm:ss")
endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")
else:
prevEndDate = system.date.parse(ganttData.getValueAt(row-1,'End Date'), "yyyy-MM-dd HH:mm:ss")
startDate = system.date.parse(system.date.addDays(prevEndDate, 1), "yyyy-MM-dd HH:mm:ss")
endDate = system.date.parse(system.date.addWeeks(startDate, weeks), "yyyy-MM-dd HH:mm:ss")
rowData.append(taskName)
rowData.append(startDate)
rowData.append(endDate)
rowData.append(percentage)
ganttData = system.dataset.addRow(ganttData, rowData)
system.db.runPrepUpdate("INSERT INTO temp_timelines (taskName, startDate, endDate, percentage) VALUES (?,?,?,?)", [taskName, startDate, endDate, percentage])
chartData = system.db.runQuery("SELECT taskName AS 'Task Name', startDate AS 'Start Date', endDate AS 'End Date', percentage AS 'Percentage' FROM temp_timelines")
event.source.parent.getComponent('Gantt Chart').data = chartData