Google App Script Error: You do not have permission to call getActiveForm?

廉价感情. 提交于 2019-12-07 15:20:32

问题


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;
}

回答1:


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.




回答2:


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.




回答3:


It is very strange but your script must have a permission to Google Drive. Insert some code in the script so app will ask a permission for it (for e.g.):

var d = DriveApp.getRootFolder();

then run the script, give the permission. After that you can delete inserted line unless you copy the code from one form to another.




回答4:


I had the same issue on a script that was attached to a spreadsheet but did something when the form that supplied that spreadsheet with data was submitted. I found under Resources->All Triggers that I had a residual Notification with an Event listed as "From Form". Since the script acts in the spreadsheet having a "From Form" event notification was causing the error.



来源:https://stackoverflow.com/questions/25712837/google-app-script-error-you-do-not-have-permission-to-call-getactiveform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!