Hi,
Thank you for reaching out to the Google Ads Scripts Forum Channel.
Upon checking the script, I would recommend placing the function getAllAdGroups() outside of your main() function and call the former function within the latter. You can refer to the snippet of code below for reference:
function main() {
getAllAdGroups();
}
function getAllAdGroups() {
const adGroupIterator = AdsApp.adGroups().get();
console.log('Total adGroups found : ' + adGroupIterator.totalNumEntities());
return adGroupIterator;
}
As an aside, I would recommend refering to our documentation of the AdGroupSelector <https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_adgroupselector> for a sample implementation which you may directly implement within your main() function as it can also yield the same results.
Let us know if you have any clarifications.
![]() |
Google Ads Scripts Team |