Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Script Error: You do not 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 great, takes information from the spreadsheet and creates a calendar event. However, when I fill out the forma and submit ( submit is the trigger) I get a error stating I do not have permission to call getActiveForm(). I own both form and 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;
}
like image 934
user2241862 Avatar asked Sep 07 '14 17:09

user2241862


People also ask

Why is my Google script not working?

There are a few possible causes for these errors: A Google server or system is temporarily unavailable. Wait for a few moments and try running the script again. There is an error in your script that doesn't have a corresponding error message.

How do I run a html file in Google App Script?

To add an HTML file to your Apps Script project, follow these steps: Open the Apps Script editor. At the left, click Add a file add > HTML.


2 Answers

I'm running into the same issue. My script just took the form response and formats into an email. Similar to the OP I do not make a single call to FormApp.getActiveForm() anywhere in my script.

This permissions issue started immediately after I added a PropertiesService.getScriptProperties() call.

While not a full fledged solution, I was able to work around this by adding a line for just FormApp.getActiveForm(), saving, then saving my triggers (to check for permissions again). I was asked to confirm Offline Access permissions for the script.

I then removed the unneeded line and the form worked fine.

like image 111
David Wantuch Avatar answered Nov 04 '22 21:11

David Wantuch


Deleting the trigger from the UI and re-adding it prompted it to request a new permission, "offline access." I granted this, and it worked from then on.

like image 30
Josh Ventura Avatar answered Nov 04 '22 20:11

Josh Ventura