2
votes

I am trying to write a very basic custom function for my google docs spreadsheet. I have a column in the spreadsheet that lists every day of the year. It's a simple function that should scroll to 'today' in the date column. However, when I try to run the query, I get an error "google is not defined".

function gotoToday() {
var now = new Date();
var now = Utilities.formatDate(now, "EST", "M/d/yyyy");
var file = SpreadsheetApp.getActiveSpreadsheet();
var sheet = file.getActiveSheet();

var query = new google.visualization.Query(sheet);
 query.setQuery('select A WHERE A= '&now);
 query.send(handleQueryResponse);  


function handleQueryResponse(response) {
  Browser.msgBox(response);
  var row = day+4; 
  file.setActiveCell(sheet.getRange(row,1));
  }
};

It's dying at the new google.visualization.Query line, saying gooogle isn't defined. Shouldn't I get those objects for free? Since it is being run in Google Docs, I can't load the jsapi via a script tag. I thought it should just be there. All the other code samples use this same method and the docs don't say anything about other scripts needing to be loaded. Any ideas would be appreciated! Thanks, D

1

1 Answers

0
votes

In addition to standard Javascript objects, APIs for many of google's offerings are provided as Services. You don't need to load other scripts to access the Script Services.

The visualization library is represented in Google Apps Script via the Charts Service. The GMail Stats tutorial is one of several that introduces use of the service.

All the other code samples use this same method...

Client-side Javascript samples can do that. No Google Apps Script example does.