Ad Group Pausing error

93 views
Skip to first unread message

Sandeep Kumar

unread,
May 28, 2025, 3:20:25 AM5/28/25
to Google Ads Scripts Forum
I am using a very simple code to pause an ad group, but it seems not to be working.


function main() {
  pauseAdGroup("Ad group 1");
}

function pauseAdGroup(name) {
  const adGroupIterator = AdsApp.adGroups()
      .withCondition(`ad_group.name = "${name}"`)
      .get();

  if (!adGroupIterator.hasNext()) {
    throw new Error(`No ad group with name "${name}" found`);
  }

  const adGroup = adGroupIterator.next();
  if (adGroupIterator.totalNumEntities() > 1) {
    console.warn(`Multiple ad groups named "${name}" found.
Using the one from campaign "${adGroup.getCampaign().getName()}".`);
  }

  adGroup.pause();
}


It produces an error - "An error occurred. Please try again later." with no details, can you help.

Nils Rooijmans

unread,
Jul 10, 2025, 4:06:51 AM7/10/25
to Google Ads Scripts Forum
Could this be the issue: you are selecting ad groups from ampaigns that have ended can not be changed?

You can prevent your selector from selecting campaigns that have ended by adding this condition:
   campaign.serving_status = 'SERVING'

Hope this helps,

Nils Rooijmans
https://nilsrooijmans.com
See my Google Ads Scripts FAQ to avoid the same mistakes I made: https://nilsrooijmans.com/google-ads-scripts-faq/

Google Ads Scripts Forum Advisor

unread,
Jul 10, 2025, 7:42:43 AM7/10/25
to adwords...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads Scripts support team.

@Nils, Thank you for your input. 

To investigate the issue further, could you please share the below details :
  • Google Ads account ID/CID
  • Name of the affected script
You can send the details via Reply privately to the author option, or direct private reply to this email. 

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-07-10 11:41:47Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01rhi8x:ref" (ADR-00318201)



Kasia Michalska

unread,
Jul 11, 2025, 2:42:55 AM7/11/25
to Nils Rooijmans via Google Ads Scripts Forum
Hello,

Where exactly do I suppose to put it in the code?

Best,
Kasia.

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/adwords-scripts/95f21413-ef23-43fb-9bd9-08f3f363e1fen%40googlegroups.com.

Kasia Michalska

unread,
Jul 11, 2025, 2:43:24 AM7/11/25
to Google Ads Scripts Forum on behalf of adsscripts
Hello,

Google Ads account: 938-728-2754
Script Name: Exclude search terms from specific campaign 

Best,
Kasia.

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.

Google Ads Scripts Forum Advisor

unread,
Jul 11, 2025, 4:49:04 AM7/11/25
to adwords...@googlegroups.com

Hi Kasia,

I would like to inform you that the method you are using to push key values to the “excludedAlready” object is causing this error. To resolve this error using the “new set ()” property instead of an empty object. Also, using ‘try’ and ‘cache’ methods will be effective. I would recommend that you use the below code.

function main() {
  const campaignName = "32154 SPM US CARTIHEAL TRAFFIC New Structure 2025";
  const termsToExclude = ["elderly", "foods", "supplement", "remedies", "seniors", "best", "failure", "surgery cost", "top knee surgeons", "tips", "timelines", "problems after", "at 14 weeks", "creams", "bone on bone", "side effects", "in my area", "old age", "why does it take so long", "do's and don ts", "near me", "at age", "at home", "at 70"];
  const matchTypes = ["broad", "phrase", "exact"];

  const campaignIterator = AdsApp.campaigns()
    .withCondition(`Name = '${campaignName}'`)
    .get();

  if (!campaignIterator.hasNext()) {
    Logger.log("Campaign not found: " + campaignName);
    return;
  }

  const campaign = campaignIterator.next();
  const excludedAlready = new Set();

  for (let i = 0; i < termsToExclude.length; i++) {
    const term = termsToExclude[i].toLowerCase();

    for (let j = 0; j < matchTypes.length; j++) {
      const matchType = matchTypes[j];
      let formattedKeyword = "";

      switch (matchType) {
        case "broad":
          formattedKeyword = term;
          break;
        case "phrase":
          formattedKeyword = `"${term}"`;
          break;
        case "exact":
          formattedKeyword = `[${term}]`;
          break;
        default:
          Logger.log(`Invalid match type encountered: ${matchType}. Skipping.`);
          continue;
      }

      const key = formattedKeyword;

      if (!excludedAlready.has(key)) {
        try {
          campaign.createNegativeKeyword(formattedKeyword);
          Logger.log(`Added negative keyword: ${formattedKeyword} (Match Type: ${matchType})`);
          excludedAlready.add(key);
        } catch (e) {
          Logger.log(`Error adding negative keyword '${formattedKeyword}' for campaign '${campaignName}': ${e.message}`);
        }
      } else {
        Logger.log(`Skipping duplicate negative keyword: ${formattedKeyword} (Match Type: ${matchType})`);
      }
    }
  }
}

I hope this helps! Kindly get back to us if you still face any errors even after using the modified code.

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5

[2025-07-11 08:48:34Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01rhi8x:ref" (ADR-00318201)



Reply all
Reply to author
Forward
0 new messages