Archive

google apps script tutorial

Few people brought to my attention google apps script so I did a little test drive today, and I am quite impressed. This suppose this is google's take on server-side JavaScript, that integrates with their google docs family and much more...

Here is one use case that I tested: loading list of users from a remote JSON service, and storing it in google spreadsheet.

// Inserts user into spreadseet.
var insertUser = function (user) {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow([user.name, user.userType]);
};

// Request service.
var service = function (url, callBack) {
  
  var response = UrlFetchApp.fetch(url),
      responseObj = JSON.parse(response.getContentText());
  
  callBack(responseObj);
};

// Main init function.
function run() {
  
  var url = 'http://www.somedomain.com/json/user/list';

  service(url, function(d){
    
    var users = d.data.users;
    
    for (var i = 0; i < users.length; i++) {
      insertUser(users[i]);
    }
  });
}

Comments: