1

We recently re-branded, which included a change of our domain. On the same Google Apps "account," we now have two domains, klht.org and kingschoolct.org, and for the moment, we have users on both.

Last year, with help from this community, I created a Google Apps Script that would write to a spreadsheet a directory of all our Google Apps users. Now, that script needs to be updated so that it will pull users from both domains (otherwise, we'll only have some of our people).

Here's the current script:

function writeToSpreadsheet(){
  var values = [];
  var users = [];
  var userlist = {users:[]};
  var nextPageToken = '';
  var listObject = {
      domain:'klht.org',
      maxResults: 500,
    }

  do {

    if (nextPageToken !== '') {
      listObject.pageToken = nextPageToken;
    }  

    userlist = AdminDirectory.Users.list(listObject);

    nextPageToken = userlist.nextPageToken;

    users = users.concat(userlist.users);

  } while (nextPageToken);

  for (var i=0; i<users.length; i++){
    values.push([users[i].name.givenName, users[i].name.familyName, users[i].primaryEmail, users[i].orgUnitPath]);   
  }

  debugger;
  var spreadsheetID = '1JLDD2wm0_udmTn9ZHvdKhL_Ok3SvKYFqkBeiA1GdnYc';
  SpreadsheetApp.openById(spreadsheetID).getSheets()[0].getRange(2, 1, values.length, values[0].length).setValues(values);
}

I tried just updating the top to add the second domain like so...

var listObject = {
  domain:'klht.org',
  maxResults: 500,
  domain:'kingschoolct.org',
  maxResults: 500,
}

...but that only pulls users from kingschoolct.org.

Any idea how I can get it to pull users from both domains?

Thanks!

Ted Parker
  • 93
  • 7
  • 1
    needs modification so you can call it twice with parameters like the domain name and also code to start writting at the correct start row.basically a pure Javascript question so add that tag to the question. – Zig Mandel Sep 18 '16 at 14:02

1 Answers1

1

I figured out the solution, which is to use the "customer" parameter rather than "domain." (Fill list of parameters here). Here's how I found my account's customerID. Works like a charm!

Community
  • 1
  • 1
Ted Parker
  • 93
  • 7