Google App Script error: don't have permission to call getActiveForm?
I am creating a script that takes information from a form and writes it to a calendar. When I run the script in the script editor, it works fine, takes information from the spreadsheet and creates a calendar event. However, when I fill in the form and submit (submit is a trigger), I get an error: I do not have permission to call getActiveForm (). I have both a form and a calendar. I appreciate any ideas.
code
function createEvent() {
var calendarToUse = "testing";
var ssUrlToUse ='https://docs.google.com/a/bay.k12.fl.us/spreadsheets
/d/1ZTDQL9G5U7RqbbKQbAfb3ERqFwpSsC3EOQxdD1zdQwA/edit#gid=441997215';
/* Get Canalnder*/
var calen = CalendarApp.getCalendarsByName(calendarToUse);
var cal = calen[0];
Logger.log(cal.getName());
/* get info from responses*/
var mySS
=SpreadsheetApp.openByUrl(ssUrlToUse).getActiveSheet()
Logger.log(mySS.getName());
var values = mySS.getDataRange().getValues();
var response = values[values.length-1];
var i=2;
var desc = response[i];
var loc = response[i+1];
var start = makeGreatDate( response[i+2], response[i+4]);
var end = makeGreatDate(response[i+3],response[i+6]);
var title = response[i+5];
/* populate calendar event*/
var event = cal.createEvent(title, start, end, {
description : desc,
location : loc
});
};
function makeGreatDate(date, time) {
var day = new Date(date);
day.setHours(time.getHours());
day.setMinutes(time.getMinutes());
Logger.log( "The Date is"+ day);
return day;
}
source to share
I faced the same problem. My script just took the form of a response and formats into an email. Similar to the OP, I don't make any calls FormApp.getActiveForm()
anywhere in my script.
This issue was resolved as soon as the call was added PropertiesService.getScriptProperties()
.
While not a complete solution, I was able to work around it by adding a line only for FormApp.getActiveForm()
, save, then save my triggers (to check the permissions again). I was prompted to confirm the permissions Offline Access
for the script.
Then I removed the unnecessary line and the form worked fine.
source to share
Very strange, but your script must have Google Drive permission. Paste the code into your script, so the app will ask for permission from it (for example):
var d = DriveApp.getRootFolder();
then run your script give permission. After that, you can delete the inserted line if you don't copy the code from one form to another.
source to share
I had the same problem on a script that was attached to a spreadsheet but did something when a form was submitted that provided that table with data. I found under Resources-> All Triggers that I have a residual notification with an event listed as "From Form". Since the script is acting on a spreadsheet with an "From Form" event message, this throws an error.
source to share