1

我正在尝试使用 Tasks API 将任务的状态设置为已完成。它表明代码已成功完成,但任务未标记为已完成。此外,当我尝试在更新后获取任务的状态时,它显示状态为“needsAction”。这是我的代码

function setTaskStatus(){
  // Suppose a task with name "MyTaskListName" is contained
  //within task list with name "MyTaskName"

  var tasklist = Tasks.Tasklists.list().getItems();
  var title = 'MyTaskListName';
  var id;
  for(var i in tasklist){
    if(title == tasklist[i].getTitle()){
      id = tasklist[i].getId();
    }
  }

  //Get the task list items
  var tasks = Tasks.Tasks.list(id).getItems();
  for(var i in tasks){
    if(tasks[i].getTitle() == 'MyTaskName'){
      tasks[i].setStatus("completed");// set status completed
      Logger.log(tasks[i].getStatus());// this shows that the task has completed
      //But it does not reflect actually
    }
  }
}
4

1 回答 1

0

我需要添加该行

Tasks.Tasks.update(tasks[i], tasklistId, tasks[i].getId());

于 2012-10-14T03:31:05.620 回答