2

I'm trying to take e-mail addresses from a spreadsheet and add them to a Google Group on a "Google Sites" page, as a method for controlling access. Is there a way to do so from the spreadsheet? I've seen the provisioning stuff for it at https://developers.google.com/google-apps/provisioning/#adding_a_member_to_a_group but have no idea how to utilize it through the scripting attached to spreadsheets in Google Docs.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Deveyus
  • 43
  • 1
  • 6

1 Answers1

2

This code is a very basic tool to add users to groups from a spreadsheet. You have to use column 1 for group Name, column 2 for users emails and let column 3 free to write a yes / no value. Note that the provisioning API is now deprecated and it would be a better idea to go directly to the new Admin SDK directory API but in the meantime this is still working if the provisioning API is activated in the google apps admin panel.

function setGroupFromSS() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Sheet1')
  var dataRange = sh.getRange(2, 1,sh.getLastRow()-1, 3)
  var data = dataRange.getValues();
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    var group = row[0];         // 1st col
    var emailAddress = row[1];  // 2nd col
    var done = row[2];          // 3th col
    if (group==""){break};
    if(done==''){
      Logger.log(i+'  '+group+'  '+emailAddress);   
//      var group = GroupsManager.getGroup(group).addMember(emailAddress);// uncomment when your SS setup is ok     
      data[i][2]='yes';
    }
  }
  sh.getRange(2,1,data.length,data[0].length).setValues(data);// update SS with "done" values
}
Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • That's excellent, I was wanting to avoid the Admin SDK because it seems to force use of OAuth, and I'd be adding people asynchronously from their submissions, so it's a bit of a sticking point. I'm off to try this now. – Deveyus Jul 29 '13 at 08:11
  • I can't get to apps control panel anymore, assuming I left it unused so my old free 'grandfathered' account has died, do you think you could explain the Admin SDK Method? – Deveyus Jul 29 '13 at 08:19