从Document UI运行时出现应用程序脚本错误

时间:2013-05-20 12:44:28

标签: google-apps-script

上周IO之后,我在文档的UI中添加了一个选项,用于将会议从昨天的会议记录表迁移到今天的会议。

当我在脚本编辑器中调试或运行时,脚本运行正常,但是,当我从UI运行时,我收到一条错误,说函数遇到错误。发生错误,我们无法保存您的更改。

Screen capture of error

以下是我的代码:

function onOpen() {
  var UI = DocumentApp.getUi();
  UI.createMenu("StandUp").addItem("Migrate Yesterday", DoMigrate).addToUi();  
}

function DoMigrate(){

var dater =new Date();  
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var month=new Array(12);
month[0]="January";
month[1]="Febuary";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="Sept";
month[9]="Oct";
month[10]="Nov";
month[11]="Dec";

var dayOfWeek = weekday[dater.getDay()];
var theMonth = month[dater.getMonth()];
  var paragraph = dayOfWeek + ", " + theMonth + " " + dater.getDate() + ", " + dater.getFullYear();
  var doc = DocumentApp.getActiveDocument();

  var tables = doc.getTables();

  var latestTable = tables[0].copy();

  for (var i = 1; i < 8.; i++)
  {
      var todayWork = latestTable.getCell(i,2).getText();

      var yesterdayCell = latestTable.getCell(i,1);
      var todayCell = latestTable.getCell(i,2);

      yesterdayCell.clear()          

      var listCount = todayCell.getNumChildren();

      for(var x = 0; x < listCount; x++)
      {
         var listText = todayCell.getChild(x).asText().getText();
         yesterdayCell.appendListItem(listText).setGlyphType(DocumentApp.GlyphType.BULLET);
      }

      todayCell.clear();


      todayCell.appendListItem("").setGlyphType(DocumentApp.GlyphType.BULLET);
  }

  doc.insertTable(0, latestTable) 
  doc.getBody().insertParagraph(0, paragraph).setBold(true).setFontSize(12);
  doc.saveAndClose();
}

感谢任何帮助。感谢

1 个答案:

答案 0 :(得分:1)

在google plus社区获得一些反馈后,我发现我的onLoad中的函数名称缺少引号。

UI.createMenu(“StandUp”)。addItem(“Migrate Yesterday”,DoMigrate).addToUi();

应该是

UI.createMenu(“StandUp”)。addItem(“Migrate Yesterday”,“DoMigrate”)。addToUi();