All campaigns in response data are same data when run AdsApp.campaigns.

11 views
Skip to first unread message

Toshi

unread,
Jul 19, 2019, 3:47:43 AM7/19/19
to Google Ads Scripts Forum
I've run this script. All campaigns in response data are same data when run AdsApp.campaigns.Is the api broken?

Script:
>  const campaigns = AdsApp.campaigns()
>    .forDateRange("20190718", "20190718")
>    .withCondition("Status = ENABLED")
>    .orderBy("Id")
>    .get();
>  
>  Logger.log("campaigns.totalNumEntities=" + campaigns.totalNumEntities());
>  while(campaigns.hasNext()) {
>    const campaign = campaigns.next();
>    Logger.log("getId=" + campaign.getId());
>    Logger.log("getName=" + campaign.getName());
>  }

Log:
> campaigns.totalNumEntities=4
> 2019/7/19 16:35:25 getId=2043077504
> 2019/7/19 16:35:25 getName=01_xxxxxx
> 2019/7/19 16:35:25 getId=2043077504
> 2019/7/19 16:35:25 getName=01_xxxxxx
> 2019/7/19 16:35:25 getId=2043077504
> 2019/7/19 16:35:25 getName=01_xxxxxx
> 2019/7/19 16:35:25 getId=2043077504
> 2019/7/19 16:35:25 getName=01_xxxxxx
> 2019/7/19 16:35:25 getId=2043077504
> 2019/7/19 16:35:25 getName=01_xxxxxx

Google Ads Scripts Forum Advisor Prod

unread,
Jul 19, 2019, 4:56:38 AM7/19/19
to adwords...@googlegroups.com

Hi Toshi,

The reason why you are encountering the issue is because of the line below.

const campaign = campaigns.next();

You would need to use var instead of const as a constant can't be changed through reassignment.

var campaign = campaigns.next();

Please let me know how it goes after trying the suggestion.

Regards,
Hiroyuki
Google Ads Scripts Team



ref:_00D1U1174p._5001U8MKXq:ref

Toshi

unread,
Jul 19, 2019, 8:31:03 AM7/19/19
to Google Ads Scripts Forum
Hi Hiroyuki,

I've resolved this issue using your solution. Thank you very much!

Regards,
Toishi

2019年7月19日金曜日 17時56分38秒 UTC+9 adsscriptsforumadvisor:
Reply all
Reply to author
Forward
0 new messages