Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

We use Google apps for enterprise, and I want to build an intranet, based on the Google sites intranet template

In the Directory area, I want that the list will be updated from my contact/company list directory.

Is it possible?

share|improve this question

1 Answer 1

up vote 5 down vote accepted
+50

The following code retrieves the users, present within the Google Apps Domain:

function doGet() {
  var app = UiApp.createApplication(); 

  var users = UserManager.getAllUsers();  
  var flexTable = app.createFlexTable().setBorderWidth(1);

  for (var i=0, len=users.length; i<len; i++) {
    var user = users[i];
    flexTable.setWidget(parseInt(i), 0, app.createLabel(user.getGivenName()
      + ' ' + user.getFamilyName()));
    flexTable.setWidget(parseInt(i), 1, app.createLabel(user.getEmail()));
  }

  app.add(flexTable);

  return app;
}

Add this script, via the Google Apps Script gadget, to your page and the people will appear. See working example: domain users by script

There are however some prerequisites:

  1. Be an administrator
  2. Enable the provisioning API: dashboard/domain settings/user settings

You can also use a script within a spreadsheet and display the users in a spreadsheet:

function getdomainUsers() {
  // set spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();

  // set sheet
  var sheet = ss.getSheets()[0];

  // set range
  var range = sheet.getRange(2, 1, sheet.getLastRow(), 2);

  // clear range
  range.clear();

  // retrieve all users and create array
  var users = UserManager.getAllUsers(), auserInfo = new Array();  

  // itterate through users  
  for (var i=0, len=users.length; i<len; i++) {
    // instantiate user
    var user = users[i];

    // add info to array
    auserInfo.push([user.getGivenName() + ' ' + user.getFamilyName(),user.getEmail()]);
  }

  // set values to sheet
  sheet.getRange(2,1,len,2).setValues(auserInfo); 
}

Set a trigger on the script, to refresh the users for lets say every 12 hours. An administrator needs to prepare the sheet once. See working example: domain users by spreadsheet

share|improve this answer
    
First script doesn't return results. can you confirm its working please? –  Saariko Nov 26 '12 at 19:08
    
See modified answer. I've added working examples. One based on a stand alone script and the other one via a spreadsheet. –  Jacob Jan Tuinstra Nov 26 '12 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.