Reputation: 45
The below given code gives me a list of sites on my primary domain, how can I get list of all sites on my domain including secondary domains?
function listSites() {
var domain = UserManager.getDomain();
var PAGE_LENGTH=200;
sheet = SpreadsheetApp.getActiveSheet();
var sites = SitesApp.getAllSites(domain,0,PAGE_LENGTH);
for(var i=0; sites.length != 0; i+=PAGE_LENGTH){
for (var j=0; j<sites.length; j++) {
sheet.appendRow([sites[j].getUrl()]);
}
sites = SitesApp.getAllSites(domain, i, PAGE_LENGTH);
}
};
Upvotes: 0
Views: 134
Reputation: 2143
The issue here is that you're only calling this for the sites on your primary domain.
The function 'Get all sites' takes an input of domain, and returns only the sites for the domain that is input.
In your sample code, the variable 'domain' is only returning the domain for the user running the application, so it won't list sites that are not on the same domain as the user running the application.
Instead, if you call the function using all of the domains on your Apps account, it will list all of the sites.
A simple example would be:
function sitesToBeListed(){
listSites('PrimaryDomain');
listSites('SecondaryDomain');
}
function listSites(domain) {
var PAGE_LENGTH=200;
var sheet = SpreadsheetApp.getActiveSheet();
var sites = SitesApp.getAllSites(domain,0,PAGE_LENGTH);
for(var i=0; sites.length != 0; i+=PAGE_LENGTH){
for (var j=0; j<sites.length; j++) {
sheet.appendRow([sites[j].getUrl()]);
}
sites = SitesApp.getAllSites(domain, i, PAGE_LENGTH);
}
};
Upvotes: 1