0
votes

I'm trying to add an autocomplete feature (a Ui in a popup window in a spreadsheet) in my Google Spreadsheet using this Google Apps Script suggest box library from Romain Vialard and James Ferreira's book:

function doGet() {
  var contacts = ContactsApp.getContacts();
  var list = [];
  for(var i = 0; i < contacts.length; i++){
    var emails = contacts[i].getEmails();
    if(emails[0] != undefined){
      list.push(emails[0].getAddress());
    }
  }
  var app = UiApp.createApplication();
  var suggestBox = SuggestBoxCreator.createSuggestBox(app, 'contactPicker', 200, list);
  app.add(suggestBox);
  SpreadsheetApp.getActive().show(app);
}


function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "my_sheet_name" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 1) {
      doGet();
   // testFunction();
    }
  }
}

But when I start editing column 1 of "my_sheet_name" nothing hapens (The testFunction() works as expected). I've already installed the Suggest Box library. So, why the doGet() function doesn't work?

Here is my test spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0AtHEC6UUJ_rsdFBWMkhfWUQ0MEs2ck5OY1BsYjRSLXc&usp=drive_web#gid=0

1
please re-read your question and edit function name ;-)Serge insas
I edit it =) And put my test spreadsheet.craftApprentice

1 Answers

1
votes

onEdit is a simple trigger , if you read the documentation you'll learn that "They cannot access any services that require authentication as that user."

And your doGet function uses ContactsApp, that's why it fails silently.

Use another name and set up an installable on Edit trigger that will ask for authorization. That said, it won't return any data to your spreadsheet (as already mentioned here in your other post and read carefully the chapter about installable triggers).

See also this doc about serverHandlers and how to implement it in UiApp.