Recurring generic error message Google Apps Script

孤者浪人 提交于 2019-12-11 15:54:50

问题


EDIT: Not sure if this matters but I am using G Suite for Nonprofits.END EDIT:::

I keep getting this error message upon attempting to manually run this script for the first time:

We're sorry, a server error occurred. Please wait a bit and try again. (line 2, file "Code")).

I have saved it and authorized its permissions already. I am simply trying to execute the script to get all of the existing responses' edit URLs.

There are no triggers associated with this. The script is intended to get the edit response URLs from a Google Form. "Edit after submit" is enabled in the Form, and it is set to public in regards to who can complete the form (not that this should matter since I am the owner of the form).

I use this script in this exact form on many other projects with no issues at all. I have also tried a different script for this task that I know works, with the same error message returned. The error message always references the line of code with the form ID/URL. I have verified the form ID. Thanks for your help.

function assignEditUrls() {
  var form = FormApp.openById('some id');
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form Responses 1');
  var data = sheet.getDataRange().getValues();
  var urlCol = 6;
  var responses = form.getResponses();
  var timestamps = [], urls = [], resultUrls = [];
  for (var i = 0; i < responses.length; i++) {
    timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
    urls.push(responses[i].getEditResponseUrl());
  }
  for (var j = 1; j < data.length; j++) {
    resultUrls.push([data[j][0] ?
      urls[timestamps.indexOf(data[j][0].setMilliseconds(0))] : ''
    ]);
  }
  sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}

回答1:


Thanks to Rubén, I was able to solve my problem. In my script I was using the incorrect Form ID. When running a script to obtain the edit response URLs from a Google Form you must view the edit form URL in the editing mode of your specific form. Extract the Form ID from this edit URL NOT the view URL or share URL etc. This is the only way your script will access the correct form with the correct permissions. Thanks again to Rubén and all others who assisted.



来源:https://stackoverflow.com/questions/52724013/recurring-generic-error-message-google-apps-script

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