How to update multiple sheets using single script

3,335 views
Skip to first unread message

Irfan Masood

unread,
Jul 13, 2014, 3:43:42 PM7/13/14
to adwords...@googlegroups.com
I made the script using following link


Now I want to update multiple sheets using same script. One is working fine but script doesn't update the second sheet. I can share the script if that can help. When I use word sheet, I meant to say multiple tabs under single spreadsheet

any quick help would be highly appreciated

thank you

Irfan

Anash Oommen

unread,
Jul 16, 2014, 2:56:30 PM7/16/14
to adwords...@googlegroups.com
Hi Irfan,

You  can use the getSheetByName method to retrieve a sheet within a Google Spreadsheet. Then use that sheet object to make updates.

Cheers,
Anash P. Oommen,
AdWords Scripts Team.

Irfan Masood

unread,
Jul 16, 2014, 6:40:07 PM7/16/14
to adwords...@googlegroups.com
Anash,

I have already tried that but it gives me error on following code of line

 var access = new SpreadsheetAccess(SPREADSHEET_URL, "Weekly"); // Weekly is 2nd sheet that I try to update using same spread sheet URL
access.writeRows(rows, emptyRow, 2);// creating issue

let me know please if I'm missing something?

Neil Goldman

unread,
Jul 17, 2014, 10:32:24 AM7/17/14
to adwords...@googlegroups.com
Hey Irfan,

I don't see anything wrong with that line. Could you please post the error message you get as well?

Cheers,
Neil

Irfan Masood

unread,
Jul 19, 2014, 5:34:45 PM7/19/14
to adwords...@googlegroups.com
Neil,

TypeError: Cannot call method "setValue" of null. (line 46)

This is the error I'm getting now.

This error occurs when I try to update 2nd sheet in spreadsheet, first one seems to be fine.

I have attached the script if that can help to describe issue. Thank you for your help on it.
script_mod_daily.php

Neil Goldman

unread,
Jul 21, 2014, 10:36:10 AM7/21/14
to adwords...@googlegroups.com
Irfan,

Is there any reason your script is enclosed in php tags? This isn't recommended for adwords scripts, they do not run php, but a modified form of Javascript.

I'm not exactly sure your error, because there is no code on line 46 and the nearest setValue call is line 38, is this where it is crashing? I also see no code where you call setValue after switching to the second sheet on line 84.

var last_check_first = spreadsheet.getRangeByName("last_check").setValue(yesterday);

Make sure your second sheet also has a named range called "last_check". The issue could be that only your first sheet has these named ranges set up on it. To offer any more advice than this, I'd need to see the proper file or error message.

Best of luck,
Neil

Irfan Masood

unread,
Jul 23, 2014, 3:45:24 PM7/23/14
to adwords...@googlegroups.com
Neil,

You can ignore php tags that were just there for another purpose. Please see the attached file and you will see I'm trying to update couple of sheets. I duplicated first sheet so last_check is part of second sheet too. It does update first one but don't work for second work. The error w.r.t file attached should be on line 91. Sorry if I couldn't make things clear, let me know if that helps and any help would be appreciated - thank you
script_mod_130714.php

Irfan Masood

unread,
Jul 23, 2014, 5:41:30 PM7/23/14
to adwords...@googlegroups.com
Neil,

besides what I posted before can you guide me on another matter please?

Below query returns me data for last 7 days, how to get data between 2 certain dates?

 "SELECT Cost, AverageCpc, Ctr, AveragePosition, Impressions, Clicks,Conversions " +
      "FROM ACCOUNT_PERFORMANCE_REPORT " +
      "DURING LAST_7_DAYS ");

Neil Goldman

unread,
Jul 24, 2014, 9:40:50 AM7/24/14
to adwords...@googlegroups.com
Hi Irfan,

The DURING  keyword can either accept a DateRange literal, such as what you have posted, or two dates with a comma separating them. Such as:

SELECT Name FROM KEYWORDS_PERFORMANCE_REPORT DURING 20120101,20120625

Here you can find an overview of AWQL: https://developers.google.com/adwords/api/docs/guides/awql

Hope this helps,
Neil
Reply all
Reply to author
Forward
0 new messages