0

When you query the Tasks Object for all of the Tasks each "Page" will contain the maxResults number of Results (default maxResults=100). If you have over 100 Tasks in a Specific TaskList or want to use pagination, you need to use pageToken to request subsequent "pages" of Tasks.

This can be done by running list() (TasksCollection Class), then retrieving the nextPageToken(). Subsequently running list() and passing in the nextPageToken, as an optional argument will give you the 2nd page of results.

  var tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
  var nextPageToken = tasksObj.getNextPageToken();
  tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20, pageToken: nextPageToken});
  var tasks = tasksObj.getItems();
  //"tasks" will hold the Tasks 20 to 40.

However, I am confused by why the documentation shows a setNextPageToken method https://developers.google.com/apps-script/class_tasks_v1_schema_tasks#setNextPageToken What can that be used for? The below code does not work because subsequent calls to list() without the nextPageToken argument will return the first set (i.e. items 1 to 20).

  var tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
  var nextPageToken = tasksObj.getNextPageToken();
  tasksObj.setNextPageToken(nextPageToken);
  tasksObj = Tasks.Tasks.list(MytaskListId, {maxResults : 20});
  var tasks = tasksObj.getItems();
  //"tasks" will hold the Tasks 1 to 20.

Am I missing something....what is the purpose of the setNextPageToken() method? Thanks.

Brian
  • 433
  • 1
  • 7
  • 16

1 Answers1

0

I believe that is a documentation issue. There are two Tasks classes one that exposes behavior and other just exposing schema/properties.

https://developers.google.com/apps-script/class_tasks

https://developers.google.com/apps-script/class_tasks_v1_schema_tasks

Use the 1st one and ignore the 2nd one. We'll look into cleaning this up soon.

Arun Nagarajan
  • 5,547
  • 1
  • 22
  • 19