How to get the spreadsheet tab name of a Google form destination using Apps Script

Viewed 2456

I have a list of Google Forms in a column in a Google spreadsheet. And I need to get the name of the spreadsheet tab that is the response destination for each of the forms.

In a for loop that runs on the list of the forms, i am using

for(i = 1; i < length-of-thelist, i++) {

var form = FormApp.openByUrl(url); //Line1
var destId = form.getDestinationId(); //Line2
var sheetName = SpreadsheetApp.openById(destId).getSheetName(); //Line3
//..... other lines to print the sheet name ......

}

On line 1, i am passing as the url the item of each cell of the list of the forms.

But this gives me an error "No item with the given ID could be found, or you do not have permission to access it." And this happens on Line1.

The second part of the error ("you do not have permission...") is not true because i am the owner of the sheet that contains the list of forms as well as the forms themselves.

Is there is a way that i can get this?

2 Answers
Related