I have a Google Sheets trigger function that on form submit places submissions in sheets based on the value selected for one of my questions. I'm trying to test my function with "Test as an Add-On" feature, but when I submit a form, I receive an error within my onSubmit
function with the error message No item with the given ID could be found, or you do not have permission to access it. (line 9, file "Code")
from trigger formSubmit
This is the line of the error,
var form = FormApp.openById(ss.getFormUrl());
which makes me think there is an authentication issue, but I'm not sure how to debug this further
Full code:
function onSubmit(e) {
//Open Marketing - Discoveries and Changes - v1
var sheet = e.range.getSheet();
//Return Spreadsheet that contains this sheet
var ss = sheet.getParent();
//Open Marketing - Discoveries and Changes - v1
var form = FormApp.openById(ss.getFormUrl());
//Destination sheet based on "Location of Change"
var destSheet = getSheet(ss, e.namedValue['Location of Change']);
//Store response in destination sheet
destSheet.appendRow(e.values);
function getSheet( spreadsheet, sheetName, headings) {
spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName(sheetName);
if (sheet == null) {
sheet = spreadsheet.insertSheet(sheetName);
if (headings && headings.constructor === Array) {
sheet.getRange(1,1,1, headings.length).setValues([headings]);
}
}
return sheet;
}
}