

--
-- 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 on the web visit https://groups.google.com/d/msgid/adwords-scripts/f318b482-0975-48c9-b554-e742167ef954n%40googlegroups.com.

Hi Michael,
I would suggest that you change the code
WHERE CampaignId IN [17369173660,17488699851,19828859756,20308819560,20319398119,20615517268,20911458687,21151794717,21199736101,21221699935,21508170474] AND segments.date DURING LAST_7_DAYS
with
WHERE campaignId IN (152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217) AND segments.date DURING LAST_7_DAYS
I hope this helps! If you still face any issues afterwards, kindly provide us with the below details.
![]() |
Google Ads Scripts Team |
Hi Michael,
Please be informed that I have removed your response from the forum as it contains the PII information.
You have misunderstood our previous suggestion of changes in the code. I would recommend that you change the code at line 5 with
const AD_GROUP_IDS = [152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217]; // Replace with your desired ad group IDs
and at line 64 with
const adGroup = AdsApp.adGroups().withIds([152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217]).get().next();
Kindly refer to the copy of the script that I have created to avoid any further confusion.
I hope this helps! If you still face any issues, feel free to contact us.
Apologies, the CID is: 287-404-3786
--
-- 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 on the web visit https://groups.google.com/d/msgid/adwords-scripts/8f490bc9-a95a-4433-a45b-cb2d51ce1b84n%40googlegroups.com.
Hi Michael,
As informed earlier, I would recommend that you change the code at line 5 with
const AD_GROUP_IDS = [152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217];
and at line 64 with
const adGroup = AdsApp.adGroups().withIds([152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217]).get().next();
Kindly refer to the copy of the script that I have created, to avoid any further confusion.
I hope this helps! If you still face any issues, feel free to contact us.
![]() |
Google Ads Scripts Team |
Hi Michael,
Please be informed that to select all the ad groups with given IDs, you have to use a while loop. I would suggest that you refer to the “AdsApp.AdGroupSelector” document for more information about selecting ad groups.
The code after adding the while loop will look like below (I am adding the whole function to avoid any confusion).
function addNegativeKeywordsToAdGroups(adGroupIds, negativeQueries) {
adGroupIds.forEach(adGroupId => {
const adGroups = AdsApp.adGroups().withIds([152056030537, 152056030697, 152056030297, 154034257126, 152056030497, 152056030457, 163723464897, 165760952133, 155375080256, 152056030257, 152056030217]).get();
while (adGroups.hasNext()) {
var adGroup = adGroups.next();
Logger.log(`Selected ad group: ${adGroup.getName()}`);
// Add negative keywords to the ad group
negativeQueries.forEach(query => {
adGroup.createNegativeKeyword(`[${query}]`);
Logger.log(`${query} --> added as an exact negative keyword`);
});}
});
}
I hope this helps! Kindly get back to us if you still face any issues.
![]() |
Google Ads Scripts Team |