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!