I'm attempting to write a Google Script that accomplishes the idea contained in this pseudocode:
access a specific Google tasklist
for each task in that tasklist {
if the task is completed {
perform an operation
}
}
I've run up against a problem -- when my script accesses the specific tasklist, I can only get information for the incomplete tasks, and the completed tasks seem to have disappeared.
The idea seemed easy enough at first. I copied the code from Google's Tasks Service webpage that is supposed to "list the tasks within a given tasklist" (https://developers.google.com/apps-script/advanced/tasks) and added one if statement within the for loop:
function listTasks(taskListId) {
var tasks = Tasks.Tasks.list(taskListId);
if (tasks.items) {
for (var i = 0; i < tasks.items.length; i++) {
var task = tasks.items[i];
Logger.log('Task with title "%s" and ID "%s" was found.',
task.title, task.id);
if (task.status == "completed") {
//perform operation
}
}
} else {
Logger.log('No tasks found.');
}
}
When I checked the logs, however, I noticed that the all the incomplete tasks were listed, but none of my completed tasks were listed. I tried running the script on a tasklist with only completed tasks and the log output was "No tasks found."
Does anyone know how to find completed tasks in a given tasklist? It seems that this should be possible, based on the fact that Zapier performs operations for completed tasks, as described in this other post: How to trigger Google Script when a Google Task is marked "completed"