FYI: Add & exclude location throws error in preview but works fine

47 views
Skip to first unread message

Sigurd Fabrin

unread,
Apr 6, 2022, 10:23:46 AM4/6/22
to Google Ads Scripts Forum
Hi, as the subject suggest, it works fine but it took me a while to find out because it keeps throwing errors.

Example code

function main() {
  var locationIds = [1000752,1000801,1000806,1000849,1004497,1004516];
  var excludeLocationIds = [1005578,1005579,1005580,1005581,1005582];
  var selectors = [
          AdsApp.campaigns(),
          AdsApp.videoCampaigns(),
          AdsApp.shoppingCampaigns()
          ];
       for (var j in selectors) {
          var iter = selectors[j]
            .withCondition('campaign.status IN ("ENABLED")')
            .get();
              while (iter.hasNext()) {
                var campaign = iter.next();
                  for (var k in locationIds) {
                    campaign.addLocation(locationIds[k]);
                  }
                  for (var y in excludeLocationIds) {
                    campaign.excludeLocation(excludeLocationIds[y])
                  }
              }
      }
}


Preview
Screenshot 2022-04-06 at 16.11.35.png

Same script after execution:
Screenshot 2022-04-06 at 16.18.30.png


Cheers
Sigurd

Google Ads Scripts Forum Advisor

unread,
Apr 8, 2022, 1:56:50 AM4/8/22
to adwords...@googlegroups.com
Hi Sigurd,

Thank you for raising your concern to our team.

I was able to replicate the issue on my end that the error encountered when previewing the script but working when running the script. I believe that the result should be the same because the preview simulates the process of running the Google Ads scripts' object.

With this, allow me to raise the issue to my team. We will revert to if I get some updates from the team about this.

Regards,
Google Logo
Ernie John
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2ZKMWu:ref
Reply all
Reply to author
Forward
0 new messages