fetch campaigns by name - all but

594 views
Skip to first unread message

Yaniv Lev-Ari

unread,
May 1, 2022, 9:30:01 AM5/1/22
to Google Ads Scripts Forum
Hi,

I am trying to fetch all campaign beside those who has GDN in their name.

I used to use the condition:
withCondition("Name DOES_NOT_CONTAIN 'GDN'")

but it changes to the new system,
so I try to write 

.withCondition("campaign.name NOT CONTAINS ('GDN')")                        
and got an error:


1.5.2022 16:27:14
InputError: Invalid condition "campaign.name NOT CONTAINS ('GDN')": unrecognized operator "NOT CONTAINS (" at U.withCondition (adsapp_compiled:3198:15) at Object.<anonymous> (adsapp_compiled:18324:54)

What did I do wrong?

To be honest, 
I am using JS more than 10 years, but I'm not a developer,
I'm a copy paster. 
I began copy paste scripts I found and made them changes for me,
based on the documentaions,
but It seems now I need to learn the language almost from scratch.. 

Thanks :)

Sigurd Fabrin

unread,
May 2, 2022, 3:52:31 AM5/2/22
to Google Ads Scripts Forum
Hi, 

You can see the available operators here https://developers.google.com/google-ads/scripts/docs/reference/adsapp/adsapp_campaignselector

For strings e.g. campaign names use (NOT) LIKE or REGEXP_MATCH

Example:
function main() {
  let campaignIter = AdsApp.campaigns()
  .withCondition('campaign.name LIKE "smth%"') // starts with this
  .withCondition('campaign.name LIKE "%smth else%"') // contains this
  .withCondition('campaign.name NOT LIKE "%smth"') // does not end with this
  .withCondition('campaign.name REGEXP_MATCH ".*(this|that).*"') // contains any of these
  .withCondition('campaign.name NOT REGEXP_MATCH ".*(name1|name2|name3).*"') // does not contain any of these
  .get();
    while (campaignIter.hasNext()) {
      let campaign = campaignIter.next();
      console.log(campaign.getName())
    }
}



Sigurd

Google Ads Scripts Forum Advisor

unread,
May 3, 2022, 2:07:56 AM5/3/22
to adwords...@googlegroups.com

Hello Yaniv,

Michael here from Google Ads scripts Team. Thank you for reaching out to us.

With regards to your concern, would you be able to try the code below if it will fit to your use case?

 

function main() {
  let campaignIterator = AdsApp.campaigns()
  .withCondition('campaign.name NOT LIKE "%GDN%"')
  .get();
    while (campaignIterator.hasNext()) {
      let campaign = campaignIterator.next();
      console.log(campaign.getName())
    }
}


 

You can also try the suggested samples by Sigurd.

 

@Sigurd, thank you for chiming in and sharing your ideas.


Regards,
 

Google Logo
Michael Angelo
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2aPM4m:ref

Yaniv Lev-Ari

unread,
May 3, 2022, 5:25:12 AM5/3/22
to Google Ads Scripts Forum on behalf of adsscripts
Thank you all
Sigurd's reply was very helpful. 

It make all those conditions clear and that was exactly what I miss from the documentation, 

As the legacy version was so intuitive.

Thanks. 

בתאריך יום ג׳, 3 במאי 2022, 9:07, מאת Google Ads Scripts Forum on behalf of adsscripts ‏<adwords...@googlegroups.com>:
--
-- 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 a topic in the Google Groups "Google Ads Scripts Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adwords-scripts/igUv5Uh-sPk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/0Gy0h000000000000000000000000000000000000000000000RBAMD200wCxWW33vReqXoODYaGM6aw%40sfdc.net.

Google Ads Scripts Forum Advisor

unread,
May 4, 2022, 1:25:12 AM5/4/22
to adwords...@googlegroups.com

Hello,

James here, also a member of the Google Ads scripts. Please let us know if you need anything else. We’re here to assist.

Regards,

Google Logo
James Howell
Google Ads Scripts Team
 


ref:_00D1U1174p._5004Q2aPM4m:ref

Martin Manchev

unread,
Jun 23, 2022, 5:00:42 PM6/23/22
to Google Ads Scripts Forum
Hello, 


I came across this conversation while researching why the  CONTAINS  operator does not work for me.
It seems odd, as the link provided above states it should be working with string values, and I've been using it for a very long time before the update of the scripts.

In my particular case, I was trying to get some keywords: 
var keywordSelector = adGroup.keywords().withCondition("Status != REMOVED")
          .withCondition("ad_group_criterion.keyword.text REGEXP_MATCH '.*test.*'").get(); - works fine

var keywordSelector = adGroup.keywords().withCondition("Status != REMOVED")
          .withCondition("ad_group_criterion.keyword.text CONTAINS 'test'") - does not work


Do I make some sort of stupid mistake, or there's any technical issue, or maybe the operator is not supported anymore and the official documentation should be updated.



Thank you in advance :))
 

Google Ads Scripts Forum Advisor

unread,
Jun 24, 2022, 4:56:27 AM6/24/22
to adwords...@googlegroups.com

Hi Martin,


Thanks for reaching out to the Google Ads Scripts.
 

So our team can better check this concern, could you provide the following?
 

  • CID.
  • Script Name.
  • Shareable links of your spreadsheet if applicable.


You can provide it via Reply privately to author option. If this option is not available, then send it instead on this email address googleadsscr...@google.com
 

Regards,

Google Logo
Darwin
Google Ads Scripts Team
 


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