0

I have a Google Form that is run on a script. Every Monday there is a trigger that happens at a specific time and what it does is it opens the sign ups and sets the destination to a new sheet in a linked spreadsheet.

I am now writing another script that will get the results from those sign ups and do something with that data. The thing is, I can't seem to figure out how to get the specific spreadsheet where the form is throwing data into.

Now if I do something like this:

var form = FormApp.getActiveForm();
var ss = SpreadsheetApp.openById(form.getDestinationId());
Logger.log(ss.getSheetName());

The output will be the name of the first sheet in that spreadsheet. While this may work for me 90% of the time, I do run a risk of somebody going and messing with the order of the sheets. For this reason, I need to retrieve the exact sheet where the form is sending data into. How can I do this?

Bagzli
  • 6,254
  • 17
  • 80
  • 163
  • From what I gather, you could store last used spreadsheet id in `User Properties` and pick it from there next time. – Parag Jadhav Jun 04 '17 at 07:41
  • @ParagJadhav I have the spreadsheet, I need the exact sheet though. – Bagzli Jun 04 '17 at 08:08
  • Then it is possible to store the sheet's `id or name` in `User Properties` – Parag Jadhav Jun 04 '17 at 09:15
  • Possible duplicate of [How to access Spreadsheet from a Google Forms submit trigger function](https://stackoverflow.com/questions/31058876/how-to-access-spreadsheet-from-a-google-forms-submit-trigger-function) – Rubén Jun 04 '17 at 15:22
  • You could name the new sheets with a date with insertSheet(SheetName). Then get all of the sheets with getSheets() and put of their names into an array. Sort the array and take the array.length-1 element and that it's. You can eliminate messing with the old sheets for now by filtering out the ones that don't have a date with something like regular expressions. – Cooper Jun 05 '17 at 03:38

0 Answers0