Where do I find the tasklist ID - google-apps-script

I am trying to create tasks in a tasklist from the google app script editor. Looks like I need the id of the tasklist to be able to add the task.
Problem is I can figure out where ti find the tasklist ID

If you want to retrieve the tasklist IDs using Google Apps Script, how about this sample script?
In order to use the sample script, before you run the script, please enable Tasks API at Advanced Google Services and API console as follows.
Enable Tasks API at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Tasks API v1
Enable Tasks API at API console
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click "Explore and enable APIs".
At left side, click Library.
At "Search for APIs & services", input "Tasks API". And click "Tasks API".
Click Enable button.
If API has already been enabled, please don't turn off.
Sample script:
After Tasks API was enabled, please run the following script.
function myFunction() {
var taskLists = Tasks.Tasklists.list().getItems();
var res = taskLists.map(function(list) {
return {
taskListId: list.getId(),
listName: list.getTitle(),
};
});
Logger.log(res)
}
Reference:
Google Tasks API
If this was not the result you want, I apologize.

Related

DriveApp Error: "We're sorry, a server error occurred. Please wait a bit and try again."

Whenever I run the following function
function getDatabases(){
var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS);
var amount = 0;
while (files.hasNext()){
if((files.next().getName()).indexOf("Database") > -1){
amount++;
}
}
return amount;
}
I get this error:
This suddenly started about a month and a half ago. The same code was working earlier so I thought I reached a quota limit but that was not the case.
got my solution
In the script -> Resources -> Advanced google services -> turn on Drive API
Click in below message " Google Cloud Platform API Dashboard" to open de cloud project for the script. With the project selected, search in the search bar "Drive API" -> ENABLE, do the same for "Google Drive API".
Done, no more "we're are sorry server error" for DriveApp functions in the script.
Also: I enabled other APIs and advanced services Drive Activity API, just in case...
I ran into this issue too...
Like Nicolás Paulino mentioned, check your "Advanced Google Services" are turned on with the Apps Script Editor UI..
As stated...from the apps script editor..
select the "Resources" menu item
then "Advanced Google Services"
then find all/all related services and toggle them on.
Then head to ...
https://console.cloud.google.com/apis/library?project={yourProjectId}
Click on the menu (top-left)
hover on "Apis & Services"
click "Library"
search for any/all related APIs you're using
I've just had your same issue and it took me forever to fix it. What worked for me was to create a copy of the spreadsheet with the bound script. After authorising everything again in the copy, it worked. Hope it helps!
If you have connected your Apps script to Google Cloud Project then you have to enable the Drive API in your console.
Drive API: https://console.cloud.google.com/apis/api/drive.googleapis.com/
Else you can go to Apps script -> Services -> Add Drive API
Source: https://developers.google.com/apps-script/guides/services/advanced
Also beware that there is a quota limit for the number of times you have called the DriveAPI. If you are not connected to any GCP project then just create a new copy of spreadsheet and try again.

Google drive code gives error when adding trigger [duplicate]

Whenever I run the following function
function getDatabases(){
var files = DriveApp.getFilesByType(MimeType.GOOGLE_SHEETS);
var amount = 0;
while (files.hasNext()){
if((files.next().getName()).indexOf("Database") > -1){
amount++;
}
}
return amount;
}
I get this error:
This suddenly started about a month and a half ago. The same code was working earlier so I thought I reached a quota limit but that was not the case.
got my solution
In the script -> Resources -> Advanced google services -> turn on Drive API
Click in below message " Google Cloud Platform API Dashboard" to open de cloud project for the script. With the project selected, search in the search bar "Drive API" -> ENABLE, do the same for "Google Drive API".
Done, no more "we're are sorry server error" for DriveApp functions in the script.
Also: I enabled other APIs and advanced services Drive Activity API, just in case...
I ran into this issue too...
Like Nicolás Paulino mentioned, check your "Advanced Google Services" are turned on with the Apps Script Editor UI..
As stated...from the apps script editor..
select the "Resources" menu item
then "Advanced Google Services"
then find all/all related services and toggle them on.
Then head to ...
https://console.cloud.google.com/apis/library?project={yourProjectId}
Click on the menu (top-left)
hover on "Apis & Services"
click "Library"
search for any/all related APIs you're using
I've just had your same issue and it took me forever to fix it. What worked for me was to create a copy of the spreadsheet with the bound script. After authorising everything again in the copy, it worked. Hope it helps!
If you have connected your Apps script to Google Cloud Project then you have to enable the Drive API in your console.
Drive API: https://console.cloud.google.com/apis/api/drive.googleapis.com/
Else you can go to Apps script -> Services -> Add Drive API
Source: https://developers.google.com/apps-script/guides/services/advanced
Also beware that there is a quota limit for the number of times you have called the DriveAPI. If you are not connected to any GCP project then just create a new copy of spreadsheet and try again.

Script for a Google Doc .makeCopy() the comments aren't copied?

Hello is possible twhen copying a Google Doc document to copy also the comments in the "copy doc."Because I've tried this with the TEMPLATE_DOC_ID which has many comments and I don't find the comments in the "copy".I am missing something?It's another method? Thanks!
//Make a copy of the template file
var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();
Unfortunately, the Google Docs copied by makeCopy() don't include the comments. So the comments and replies are required to be inserted to the copied file, after the file was copied. In order to implement this, please enable Drive API at Advanced Google Services and API console.
Enable Drive API v2 at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Drive API v2
Enable Drive API at API console
About Drive API, in your environment, this might have already been enabled.
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click Enable APIs and get credentials like keys.
At left side, click Library.
At Search for APIs & services, input "Drive". And click Drive API.
Click Enable button.
If API has already been enabled, please don't turn off.
Sample script :
var documentId = DriveApp.getFileById(TEMPLATE_DOC_ID).makeCopy().getId();
// Added script
var commentList = Drive.Comments.list(TEMPLATE_DOC_ID);
commentList.items.forEach(function(item) {
var replies = item.replies;
delete item.replies;
var commentId = Drive.Comments.insert(item, documentId).commentId;
replies.forEach(function(reply) {
Drive.Replies.insert(reply, documentId, commentId).replyId;
});
});
Note :
Unfortunately, the create time and modified time couldn't updated. So the date becomes the created date.
References :
Advanced Google Services
Drive API
Comments: insert
Replies: insert
If this was not what you want, I'm sorry.

Is there a way to add multiple labels at once to a Gmail thread in a google app script?

I am trying to add some labels to Gmail threads in a google-app script programmatically.
Using thread.addLabel function right now.
Because I am adding multiple labels to many threads, this approach is first slow and second inefficient in quota usage. I have to call thread.allLabel for every label for every thread.
Is there a way to add multiple labels to Gmail threads / messages together?
The Gmail API has a thread.modify function that can be used to add multiple labels. Is there something similar in google apps script ?
You want to add several labels to a thread using Google Apps Script. If my understanding is correct, how about using Gmail API of Advanced Google Services? In GmailApp, I couldn't find methods for adding several labels to a thread. So I propose this. I think that you can achieve it using gmail.users.messages.modify. The sample script is as follows. In order to use this script, please enable Gmail API at Advanced Google Services and API console.
Enable Gmail API v1 at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Gmail API v1
Enable Gmail API at API console
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click Enable APIs and get credentials like keys.
At left side, click Library.
At Search for APIs & services, input "Gmail". And click Gmail API.
Click Enable button.
If API has already been enabled, please don't turn off.
If now you are opening the script editor with the script for using Gmail API, you can enable Gmail API for the project by accessing this URL https://console.cloud.google.com/apis/api/gmail.googleapis.com/overview
Flow of script :
Retrieve label list.
Retrieve label IDs using label names.
Add the labels to a thread.
Sample script :
var userId = "me";
var threadId = "### thread ID ###"; // Please input a thread ID.
var labels = ["### label name 1 ###", "### label name 2 ###"]; // Please input label names here.
var labelList = Gmail.Users.Labels.list(userId).labels;
var labelIds = labels.map(function(e){return labelList.filter(function(f){return f.name == e})[0].id});
Gmail.Users.Messages.modify({"addLabelIds": labelIds}, userId, threadId);
Note :
This is a simple sample script. So please modify it to your environment.
References :
Advanced Google Services
Gmail API
If I misunderstand your question, I'm sorry.

Sheets function working in standalone Google Script but NOT when script is bound to a Google Sheet

I have this piece of code that is working perfectly when I use it in a standalone Google Script running as a web-app :
function getSubjectsRollNosFromGradeSheet() {
var spreadsheetId = '171hWWH8bV6kM1JJ2dvL80q3BoWC6eEc0U7l7wCTaXHE';
var rangeSubject = 'GradesT1!G1:AA1';
var values = Sheets.Spreadsheets.Values.get(spreadsheetId, rangeSubject).values;
However when I write this same code in a Script that is embedded inside another Google sheet (not the one being accessed for data) attached to a Google Form I get an error :
function updateForm(){
// call your form and connect to the drop-down item
var form = FormApp.openById("1VV_LeFJODZcIzfcYOh8vHEkhl033Lx4ZsXaY4Pm1ZUE");
var subList1 = form.getItemById("497738674").asListItem();
//pull data from another sheet
var spreadSheetID = "1EJSx62rZuLSKIgel7LH8hE7-68lupz4buutmVQBqi2I";
var rangeSubs = 'Sheet1!A1:A';
var subValues = Sheets.Spreadsheets.Values.get(spreadSheetID, rangeSubs).values;
I get this error
ReferenceError: "Sheets" is not defined. (line 16, file "Code")
Why is the Sheets object available in the first case but not in the second case and how should I change my code to overcome this error.
Sheets is one of methods of Advanced Google Services. So in order to use Sheets of Advanced Google Services, please enable Sheets API for Advanced Google Services and API console as follows.
Please do this at the bound script which included the script of your question.
Enable Sheets API v4 at Advanced Google Services
On script editor
Resources -> Advanced Google Services
Turn on Google Sheets API v4
Enable Sheets API v4 at API console
Enable Sheets API v4 at API console
On script editor
Resources -> Cloud Platform project
View API console
At Getting started, click Enable APIs and get credentials like keys.
At left side, click Library.
At Search for APIs & services, input "sheets". And click Google Sheets API.
Click Enable button.
References :
Advanced Google Services : https://developers.google.com/apps-script/guides/services/advanced
Sheets API v4: https://developers.google.com/sheets/api/
If I misunderstand your question, I'm sorry.