2

I am trying to set the status of a task as completed using Tasks API. It shows that the code has completed successfully, but the task is not being marked as completed. Also, when I try to get the status of the task after update, it shows status as "needsAction". Here is my code

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
    }
  }
}
Cartman
  • 498
  • 8
  • 10
  • I've ran your code and the task was successfully marked "completed". Could you please make sure you are not mixing up the names of Task and TaskList. (Judging by your inline comment at the top of the function, you are in fact mixing the two up) – Anton Soradoi May 07 '12 at 22:06
  • I didn't see your comment until now... the comment is mixed, but the code is right ;) and not working for me – Cartman May 13 '12 at 16:41

1 Answers1

0

I needed to add the line

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

pinoyyid
  • 21,499
  • 14
  • 64
  • 115