1

I would like use Apps Script to make changes to the status, dates, or note of a task with known id.

I have tried using the following code which shows a change in status when I log the task in the script but the task is not updated in the calendar

task = Tasks.Tasks.get(tasklistID, taskid)

task.setStatus("completed")
tehhowch
  • 9,645
  • 4
  • 24
  • 42
Sheils
  • 323
  • 2
  • 22

1 Answers1

1

In order to modify "the status, dates, or note of a task", how about using the patch method of Tasks API?

In order to use the sample script, before you run the script, please enable Tasks API at Advanced Google Services and API console. Please confirm it at here.

Sample script:

This sample script modifies the status, dates and note of a task of taskId in a list of tasklistId.

var tasklistId = "###";
var taskId = "###";
var resource = {
  status: "completed", // This is either "needsAction" or "completed"
  due: "2019-04-15T00:00:00Z", // Due date of the task (as a RFC 3339 timestamp).
  notes: "sample note",
}
var res = Tasks.Tasks.patch(resource, tasklistId, taskId);
  • status: Status of the task. This is either "needsAction" or "completed".
  • due: Due date of the task (as a RFC 3339 timestamp). Optional.
  • notes: Notes describing the task. Optional.

Note:

  • In this sample script, it supposes that you have already known tasklistId and taskId.

References:

If I misunderstood your question, I apologize.

Edit:

When you want to back the completed task to "needsAction". Please use the following script.

Sample script:

var resource = {
  status: "needsAction",
  completed: null,
};
Tasks.Tasks.patch(resource, tasklistId, taskId);
Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Thanks Tanaike, that's exactly what I was after – Sheils Apr 14 '19 at 03:25
  • @Sheils Thank you for replying. I'm glad your issue was resolved. – Tanaike Apr 14 '19 at 03:47
  • Just noticed that the patch don't work when I try to reset the task to incomplete with status:needsAction I get an error Execution failed: API call to tasks.tasks.patch failed with error: Invalid Value. Can you address that in a one liner or should I make a new post – Sheils Apr 14 '19 at 04:26
  • @Sheils I added a sample script for resetting status to "needsAction". Could you please confirm it? – Tanaike Apr 14 '19 at 05:54