【问题标题】:Error type of "We're sorry, a server error occurred. Please wait a bit and try again. "错误类型为“抱歉,发生服务器错误。请稍候,然后重试。”
【发布时间】:2014-05-21 20:27:48
【问题描述】:

当我运行我的代码时,我不断收到此错误“我们很抱歉,发生服务器错误。请稍等,然后重试。”我真的需要一些帮助。

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

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

   }




  } 

不胜感激!

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    这部分可能会导致问题:

    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 itself 将一一对应,所以 @987654327 毫无意义@ 因为它实际上意味着 TW_data["Samsung"],因此是错误。此外,row_number"Samsung"2 的总和,这不太可能。

    要使其正常工作,您只需将 for 循环的开头替换为 for (j=0;j&lt;TW_data.length;j++) 其余代码快速浏览一下就可以了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-02
      • 2013-11-02
      • 1970-01-01
      • 2021-01-21
      • 2020-12-07
      • 2021-03-14
      相关资源
      最近更新 更多