0

After IO last week, I added an option to the UI of a document to migrate meetings from yesterday's minutes table to today's.

The script runs fine when i debug or run in the script editor, however, when i run from the UI, i get an error saying function has experienced an error. An error has occurred and we cannot save your changes.

Screen capture of error

Below is my code:

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

Any help is appreciated. Thanks

2
  • Sorry I missed out on some code: Commented May 20, 2013 at 13:11
  • Looks like I was missing quotes around the function name to call in the AddItem line of the onOpen. Commented May 20, 2013 at 14:53

1 Answer 1

1

After some feedback on the google plus community, it turns out i was missing quotes around the function name in my onLoad.

UI.createMenu("StandUp").addItem("Migrate Yesterday", DoMigrate).addToUi();

should have been

UI.createMenu("StandUp").addItem("Migrate Yesterday", "DoMigrate").addToUi();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.