I am trying to create an external "undo" button for the user to undo a task resize.
I am able to get the original end date (prior to resize) from the taskResizeEnd event. Is there a function I can then call to edit the end date of that specific task? Visually, I want the bar to shift back to its original position.
The method changes endDate field value and then launches changes propagation that recalculates all the related project data. The method returns a Promise to wait for the propagation completion:
await task.setEndDate(new Date())
// here all the related data changes is applied
Changes propagation will be scheduled automatically when you change endDate.
Son in most of the cases just changing fields is enough.
Yet if you need to get recalculated values right after the change you'll need to wait till recalculation is done. For example:
task.endDate = new Date()
console.log(task.duration) // this will not dump new duration recalculated after endDate change ..since changes propagation is not done yet (it's just scheduled)
You can trigger changes propagation manually to fix the above scenario:
task.endDate = new Date()
await project.commitAsync()
console.log(task.duration) // this will dump new recalculated duration
Or use setEndDate method which will give you the same result and look a bit shorter:
await task.setEndDate(new Date())
console.log(task.duration) // this will dump new recalculated duration