2

I am trying to change the parent of a new Google task created using Google Scripts. Since the parent must be changed using "move," I'm trying the following:

var oldtask = Tasks.Tasks.get(TASK_LIST_ID, TASK_ID);
var newtask = Tasks.newTask();
newtask.title = oldtask.title;
newtask.position = oldtask.position;
newtask.notes = oldtask.notes;
Tasks.Tasks.move (TASK_LIST_ID,newtask.id,oldtask.parent);

The last line throws Extra args block must be a javascript object literal. when running it from the Google Scripts editor. I have tried multiple different formats and have the feeling this is an easy fix.

This is my first post here so please let me know if you need more info.

fleapower
  • 65
  • 6

1 Answers1

0

I believe I've figured this out. A Javascript object literal is a string in the JSON style. So for example:

var arg = {
  showCompleted: false
};

or used within context:

var arg = {
      showCompleted: false
    };
var id = 'MY_TASK_ID'
var tasks = Tasks.Tasks.list(id,arg);
if (tasks.items) {
  for (var i = 0; i < tasks.items.length; i++) {
    var task = tasks.items[i];
    Logger.log(task.title)
  }//for
}//if

In this case, the code will display in the logger only the titles of those tasks that are incomplete, the showCompleted: false excluded any completed tasks

References:
https://www.w3schools.com/js/js_objects.asp
https://www.dyn-web.com/tutorials/object-literal/

API with all the arguments
https://developers.google.com/tasks/v1/reference/tasks/list

I hope this helps

Gareth Palmer
  • 31
  • 1
  • 6