我有一个脚本通过电子邮件将表格作为PDF附件发送。
过去常常会工作到一周左右。现在我收到错误: 我们很抱歉,发生了服务器错误。请稍等一下再试一次。 (第66行,文件" FeedbackEmail")。这一行是:
function fdbkEmail() {
// Set the Active Spreadsheet
var originalSpreadsheet = SpreadsheetApp.getActive();
// Set the Sheet you want to email
var sourcesheet = originalSpreadsheet.getSheetByName("Feedback");
// Range to get (Does not work, Emails the entire sheet)
var sourcerange = sourcesheet.getRange('A1:M54');
var sourcevalues = sourcerange.getValues();
var data = sourcesheet.getDataRange().getValues();
// The email senders name is fetched to display in the end of the email body (Generally the PM's Name)
var emailsendername = originalSpreadsheet.getRange("BackEnd!B2").getValue();
// The name of the person who the feedback was for
var feedbackreciever = originalSpreadsheet.getSheetByName("Feedback").getRange('D1').getValue();
// Name of the Project to be defined
var projectname = originalSpreadsheet.getSheetByName("Feedback").getRange('I1').getValue();
// Set the message to attach to the email.
var message = 'Hi,' + '\n' + '\n Please find attached PDF document of the feedback provided to ' + feedbackreciever + '\n' + '\nRevert for any clarifications.' + '\n' + '\n' + '\nRegards!' + '\n' + emailsendername;
// Construct the Subject Line
var subject = projectname + ' | Feedback | ' + feedbackreciever;
var backEndSheet = originalSpreadsheet.getSheetByName("BackEnd");
// Request for additional Recipient Email Address
var addRecp = Browser.inputBox('Add Recipients?', 'Enter email addresses seperating each by a comma and followed by a space (, )', Browser.Buttons.OK_CANCEL);
if (addRecp == "cancel") {
return;
}
backEndSheet.getRange('F2').setValue(addRecp);
var emailAdd = backEndSheet.getRange('F2').getValues().toString();
// Google scripts can't export just one Sheet from a Spreadsheet
// Create a new Spreadsheet and copy the current sheet data range into it.
var newSpreadsheet = SpreadsheetApp.create("Temp Feedback"); // can give any name.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A1:M54").getValues();
var sheet = sourcesheet.copyTo(newSpreadsheet);
var destrange = sheet.getRange('A1:M54');
destrange.setValues(sourcevalues);
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
// Make PDF, currently called "Planning Poker Estimates"
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName(subject + ".pdf");
// Delete the wasted sheet we created, so our Drive stays tidy.
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
// Send the freshly constructed email (This is the line Error Occurs)
MailApp.sendEmail(emailAdd, subject, message, {attachments: [theBlob]});
//Show a Pop-Up message on Email Confirmation
{
Browser.msgBox('Email Sent', 'A PDF Copy of the Feedback has been sent successfully to : ' + emailAdd, Browser.Buttons.OK);
}
}
在我的故障排除过程中进行了以下观察:
我在
上尝试过排查我不明白这个的原因。我做错了什么或遗失了什么?
印张:
SCRIPT:
my_obj.child_object = mock.Mock()
my_obj.child_object.meth1_call = mock.Mock()
my_obj.child_object.meth1_call().meth2_call = mock.Mock(return_value= [custom_list])