Google Apps script: “We're sorry, a server error occurred. Please wait a bit and try again”

泪湿孤枕 提交于 2021-01-27 18:09:05

问题


I am using Google Apps script to set up a spreadsheet merge to a from letter that will be emailed. I copied a similar script and added my info. Everytime I try to save it I get the "We're sorry a server error occurred. Please wait a bit and try again."

//  dixie@yellowdogknitting.com
//  Job Offer Letter

//  Get template from Google Docs and name it
var docTemplate = "1Y5ohbBWPeLSvNijge6I3ueQpulFzeZTky7853sKGSj8";
var docName = "HR_2_Job_Offer_form_letter";

//  When Form Gets Submitted
function onFormSubmit(e) {

//  Get information from form and set our variables

var email_address = e.values[10];
var date = e.values[1];
var first_name = e.values[2];
var last_name = e.values[3];
var job_title = e.values[11];
var status = e.values[13];
var hourly_wage = e.values[14];
var start_date = e.values[15];

//  Get document template, copy it as a new temp doc, and save the doc's id
var copyId = DocList.getFileById(docTemplate)
        .makeCopy(docName+' for '+first_name last_name)
        .getId();

//  Open the temporary document
var copyDoc = DocumentApp.openById(copyId);

//  Get the document's body section
var copyBody = copyDoc.getActiveSection();

//  Replace place holder keys, in our google doc template
copyBody.replaceText('keyTodaysDate', date);
copyBody.replaceText('keyFirstName', first_name);
copyBody.replaceText('keyLastName', last_name);
copyBody.replaceText('keyJobTitle', job_title);
copyBody.replaceText('keyStatus', status);
copyBody.replaceText('keyHourlyWage', hourly_wage);
copyBody.replaceText('keyStartDate', start_date);

//  Save and close the temporary document
copyDoc.saveAndClose();

//  Convert document to PDF
var pdf = DocList.getFileById(copyId).getAs("application/pdf")'

//  Attach PDF and send the email
var subject = "Job Offer";
var body = "Here is the Job Offer for " + first_name last_name + "";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});

//  Delete temp file
DocsList.getFileById(copyId).setTrashed(true);
}

回答1:


This happens when there's some kind of Javascript error thrown behind the scenes.

In order to work out which line has the error, put a breakpoint at the first line of code (you do this by clicking just to the left of the line number.)

Then step through the code and see when the server error pops up. Then we can help you work out what's wrong with that particular line.



来源:https://stackoverflow.com/questions/19553828/google-apps-script-were-sorry-a-server-error-occurred-please-wait-a-bit-and

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