错误类型:对不起,出现服务器错误。请稍等,然后重试。"错误、重试、请稍等、类型

2023-09-03 10:33:29 作者:Weirdo(怪人)

我一直收到这样的错误:"很抱歉,出现服务器错误。请稍等片刻,然后重试。"在我运行代码时,我真的需要一些帮助。

我怀疑错误是邮件应用程序造成的

    function onOpen() {
     var submenu = [{name:"Report", functionName:"responseMech"}];
     SpreadsheetApp.getActiveSpreadsheet().addMenu('Generator', submenu);  

    }



   function responseMech(){

 var response = Browser.inputBox('Report Generator', 'Please enter the Trackwise record             number you are searching for', Browser.Buttons.OK_CANCEL);
    report(response)
 }


  function report(response) {
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses");



   var TW_data = ss.getRange(2,3,ss.getLastRow(),1).getValues();

 for (j in TW_data){

if(response == TW_data[j] && response != ""){
  //Main program can take place here

  var row_number = j + 2;

  var report_heading = new Array();
  var report_data = new Array();


  for (var i = 0; i < ss.getLastColumn(); ++i) {
    report_heading.push([]);
    report_data.push([]);
  }

  for (var i = 0; i < ss.getLastColumn(); ++i) {
    report_heading[i][0]=ss.getRange(1,i+1).getValues();
    report_data[i][0]=ss.getRange(row_number,i+1).getValues();
  }


  var final_heading = new Array();
  var final_data = new Array();



  for(var i = 0; i < ss.getLastColumn(); ++i){
    if(report_data[i][0] != ""){
      final_heading.push(report_heading[i][0]);
      final_data.push(report_data[i][0]);
    }
  }


  var doc = DocumentApp.openById("1vVs5A94GcPhsdowZjMDXnlTdL7iH_AiT52uemWgcVYU");



  doc.setText('')
  InputDataToReport(doc, final_heading, final_data);
  var sender = Session.getActiveUser().getEmail();

  var subject = " Report for TW# " + response;
  var message = "Please see attached";
//  


 var file = DriveApp.getFileById('1vVs5A94GcPhsdowZjMDXnlTdL7iH_AiT52uemWgcVYU');




  //Send the freshly constructed email 
MailApp.sendEmail(sender, subject, message, {
 name: 'Automatic Emailer Script',
 attachments: [file.getAs(MimeType.PDF)]
 });


}




     } 

  }



  function InputDataToReport(doc,heading, responses) { 
    //define header cell style which we will use while adding cells in header row
      //Backgroud color, text bold, white
     var headerStyle = {};
      headerStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#336600';
        headerStyle[DocumentApp.Attribute.BOLD] = true;
        headerStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#FFFFFF';

      //Style for the cells other than header row
       var cellStyle = {};
   cellStyle[DocumentApp.Attribute.BOLD] = false;
    cellStyle[DocumentApp.Attribute.FOREGROUND_COLOR] = '#000000';

       //By default, each paragraph had space after, so we will change the paragraph style to add zero space
     //we will use it later
    var paraStyle = {};
   paraStyle[DocumentApp.Attribute.SPACING_BEFORE] = 0;
        paraStyle[DocumentApp.Attribute.SPACING_AFTER] = 0;
    paraStyle[DocumentApp.Attribute.LINE_SPACING] = 1;


     //get the body section of document
    var body = doc.getBody();

    //Add a table in document
     var table = body.appendTable();



    for(var i=0; i<heading.length; i++){
var tr1 = table.appendTableRow();
var td1 = tr1.appendTableCell(heading[i][0]);
td1.setAttributes(headerStyle);
var paraInCell = td1.getChild(0).asParagraph();
paraInCell.setAttributes(paraStyle);

var tr2 = table.appendTableRow();
var td2 = tr2.appendTableCell();
var para2 = td2.appendParagraph(responses[i][0]);
td2.setAttributes(cellStyle);
var paraInCell2 = td2.getChild(0).asParagraph();
paraInCell2.setAttributes(paraStyle);

   }




  } 

感谢您在这方面的帮助!

推荐答案

人人商城报错 服务器暂时无法处理您的请求,请稍后再试,到底能不能解决呢

此部件可能会导致问题:

for (j in TW_data){

if(response == TW_data[j] && response != ""){
  //Main program can take place here

  var row_number = j + 2;
在本例中,每个j都是该行中的实际值。因此,如果该列包含以下3行:"Apple""Samsung""Sony"j本身将逐一包含它们,因此执行TW_data[j]是没有意义的,因为它实际上意味着TW_data["Samsung"],因此出现错误。此外,使用row_number"Samsung"2相加,这是不太可能的。

要使其正常工作,只需将for循环的开头替换为 for (j=0;j<TW_data.length;j++)因为代码的其余部分看起来没有问题

 
精彩推荐
图片推荐