I hope this going to be an easy one, however I could not find answer on these forums nor on Google.
The problem.
A code changing Google Form title does work when a function is called "manually" but doesn't work when called via onFormSubmit trigger (the trigger was set-up manually).
I'm the owner of the sheet, however the form is shared with me (I'm an editor, not the owner).
Any ideas please? :)
//the below changes the form title when run directly from editor
function changeFormTitle() {
var sheet = SpreadsheetApp.getActive().getSheetByName("TEST")
var url = sheet.getFormUrl()
console.log(url) // https://docs.google.com/forms/d/---correctID---/viewform
var form = FormApp.openByUrl(url)
form.setTitle("new title ***")
}
//the below code throws an exception when executed via onFormSubmit trigger
function onFormSubmit(e) {
var sheet = e.range.getSheet() //get sheet where a form response was received
var url = sheet.getFormUrl()
console.log(url) // https://docs.google.com/forms/d/---sameIDasAbove---/viewform
try {
var form = FormApp.openByUrl(url)
form.setTitle("new title ***")
} catch (err) { console.log(err) }
//throws: { [Exception: No item with the given ID could be found. Possibly because you have not edited this item or you do not have permission to access it.] name: 'Exception' }
}