Kindly need your help. I've copied a script from the internet, and make a modification from that. But when 1 run the scripts, 1 script always time out while the other one always run successfully, even though both scripts are similar and the one running successfully has more variable to export.
function main() {
// Only CONTAINS and DOES_NOT_CONTAIN operators are supported.
var accountIterator = AdsManagerApp.accounts()
.withCondition("LabelNames CONTAINS 'Controlled by Script - SEM VP'")
.get();
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
var now = new Date();
var from = new Date(now.getTime() - 31 * MILLIS_PER_DAY);
var to = new Date(now.getTime() - 1 * MILLIS_PER_DAY);
var timeZone = AdsApp.currentAccount().getTimeZone();
// Name of the specific sheet in the spreadsheet.
var SHEET_NAME = 'Raw - SEM VP';
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = ss.getSheetByName(SHEET_NAME);
sheet.clearContents();
sheet.appendRow(['Date', 'Campaign Name', 'Cost']);
while (accountIterator.hasNext()) {
var account = accountIterator.next();
var accountName = account.getName() ? account.getName() : '--';
Logger.log('%s',accountName);
MccApp.select(account);
var report = AdsApp.report(
"SELECT Date, CampaignName, Cost " +
"FROM CAMPAIGN_PERFORMANCE_REPORT " +
"WHERE Cost > 0 " +
"DURING " + Utilities.formatDate(from, timeZone, 'yyyyMMdd') + ','
+ Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
//report.exportToSheet(sheet);
//Logger.log('%s %s',Utilities.formatDate(from, timeZone, 'yyyyMMdd'),Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
var rowsIterator = report.rows();
while (rowsIterator.hasNext()) {
var row = rowsIterator.next();
var dt = row['Date'];
var cnm = row['CampaignName'];
var cs = row['Cost'];
//Logger.log('%s %s %s',dt,cnm,cs);
sheet.appendRow([dt, cnm, cs]);
}
}
}
function main() {
// Only CONTAINS and DOES_NOT_CONTAIN operators are supported.
var accountIterator = AdsManagerApp.accounts()
.withCondition("LabelNames CONTAINS 'Controlled by Script - SEM VP'")
.get();
var MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
var now = new Date();
var from = new Date(now.getTime() - 46 * MILLIS_PER_DAY);
var to = new Date(now.getTime() - 1 * MILLIS_PER_DAY);
var timeZone = AdsApp.currentAccount().getTimeZone();
// Name of the specific sheet in the spreadsheet.
var SHEET_NAME = 'Raw SEM VP';
var ss = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = ss.getSheetByName(SHEET_NAME);
sheet.clearContents();
sheet.appendRow(['Date', 'Account Name', 'CampaignName', 'Cost', 'Channel Type', 'Conversion Value', 'Conversions']);
while (accountIterator.hasNext()) {
var account = accountIterator.next();
var accountName = account.getName() ? account.getName() : '--';
Logger.log('%s',accountName);
MccApp.select(account);
var report = AdsApp.report(
"SELECT Date, AccountDescriptiveName, CampaignName, Cost, ConversionValue, Conversions " +
"FROM CAMPAIGN_PERFORMANCE_REPORT " +
"WHERE Cost > 0 " +
"DURING " + Utilities.formatDate(from, timeZone, 'yyyyMMdd') + ','
+ Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
//report.exportToSheet(sheet);
//Logger.log('%s %s',Utilities.formatDate(from, timeZone, 'yyyyMMdd'),Utilities.formatDate(to, timeZone, 'yyyyMMdd'));
var rowsIterator = report.rows();
while (rowsIterator.hasNext()) {
var row = rowsIterator.next();
var dt = row['Date'];
var anm = row['AccountDescriptiveName'];
var cnm = row['CampaignName'];
var cs = row['Cost'];
var ct = row['CampaignName'].substring(0, 12);
var cv = row['ConversionValue'];
var co = row['Conversions'];
//Logger.log('%s %s %s %s %s',dt,anm,cnm,cs,ct,cv,co);
sheet.appendRow([dt, anm, cnm, cs, ct, cv, co]);
}
}
}