Account object has different methods while working in parallel

49 views
Skip to first unread message

Krzysztof Bycina

unread,
Mar 13, 2020, 6:15:07 AM3/13/20
to Google Ads Scripts Forum
Hi AdsScripts team,

I'd like to try working in parallel on my accounts.

Before my script was making changes in series.

I had a code like that:

    var accountSelector = AdsManagerApp.accounts()
        .withCondition("LabelNames CONTAINS '" + LABELNAME + "'");
    var accountIterator = accountSelector.get();



    while (accountIterator.hasNext()) {

        var account = accountIterator.next();


How can I access the same account object for each account while working in parallel, please?

Currently, I select the account like that:

var account = AdsApp.currentAccount();

Unfortunately, it doesn't have the same methods.


Can you help me with it, please?

Thank you,
Krzysztof

Google Ads Scripts Forum Advisor

unread,
Mar 13, 2020, 12:31:24 PM3/13/20
to adwords-scripts+apn2wqfrp7lvxych...@googlegroups.com, adwords-scripts+apn2wqfrp7lvxych...@googlegroups.co, adwords...@googlegroups.com
Hi Krzysztof,

The executeInParallel method is an account selector method. It is designed to work on accounts in bulk, hence you cannot access a specific account within the execute in parallel method. You can read more about execute in parallel here

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UXUydI:ref

Krzysztof Bycina

unread,
Mar 13, 2020, 1:26:32 PM3/13/20
to Google Ads Scripts Forum
Will it work if I do something like that, please?

var accountName = AdsApp.currentAccount().getName()
var account = AdsManagerApp.accounts().withCondition("Name = '"+ accountName + "'").get().next();


Krzysztof Bycina

unread,
Mar 14, 2020, 1:05:04 PM3/14/20
to Google Ads Scripts Forum

In other words, is it possible to the access each account labels while using Parallel?


Or it's just not possible at all?


Thank you.

Google Ads Scripts Forum Advisor

unread,
Mar 16, 2020, 1:25:07 AM3/16/20
to adwords-scripts+apn2wqfrp7lvxych...@googlegroups.com, adwords-scripts+apn2wqfrp7lvxych...@googlegroups.co, adwords...@googlegroups.com
Hi Krzysztof,

I work with Matt and allow me to assist you in the mean time.

Could you confirm if what you want to retrieve is the labels created on each account? If yes, then you may try to refer to the sample implementation below to retrieve labels while using parallel :

function main() {
var accountSelector = AdsManagerApp.accounts() .withLimit(50);
accountSelector.executeInParallel('processResults', null);
}

function processResults() {
accountSelector = AdsManagerApp.accounts().get().next();
AdsManagerApp.select(accountSelector);

var labelSelector = AdsApp.labels();
var labelIterator = labelSelector.get();

while (labelIterator.hasNext()) {
 var label = labelIterator.next();
 Logger.log(label.getName());
 }
}

Let me know if you have further questions.

Thanks,
Peter
Reply all
Reply to author
Forward
0 new messages