Change campaign name adwords scripts

I'm trying to create a script on Google Adwords that changes the campaign name. But right now the script is doing nothing. What is wrong?

function main() {

  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "teste"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var newCampaignName = 'teste2';
    campaign.setName(newCampaignName);

  }

}

Answers


A while loop is the most common element used after the Iterator. Try this out instead:

function main() {

  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "teste"')
      .get();
 while (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var newCampaignName = 'teste2';
    campaign.setName(newCampaignName);
    Logger.log("Campaign Name Changed")

  }

}

I have also included a "Logger.log" to display the output of the while loop. If that isn't triggering, then there is something wrong with your Iterator condition; maybe you dn't have a campaign with the name you've used.


If you wish to rename a campaign, you must provide the ID. This field can be selected using the value "Name". This field can be filtered on.


Need Your Help

How can I {x:Bind} to a DataTemplate's root type in UWP?

c# xaml windows-store-apps uwp

I have a template that receives a string as its data type: