I am currently facing some difficulties in figuring out how to display objects from an Array on separate rows within a spreadsheet using Google AdWords.
var SPREADSHEET_URL = "xxxx";
function main(){
var spreadsheet = SpreadsheetApp.openByUrl(SPREADSHEET_URL);
var sheet = spreadsheet.getSheetByName('Sheet1');
var headrows = [
['Kund',
'Spend',
'Budget',
'Average',
'Prognos',
'Status']];
var range = sheet.getRange('A1:F1');
range.setValues(headrows);
Logger.log(getCalc().accountArr.name);
}
function getCalc(){
var monthObj = {};
var sevenObj = {};
var nameObj = {};
var progObj = {};
var accountArr = [];
var dagarPrognos = getDagar().daysLeft;
var accountIterator = MccApp.accounts()
.withIds(['xx', 'xx','xx'])
.get();
while(accountIterator.hasNext()){
var account = accountIterator.next()
nameObj = account.getName();
var statsMonth = account.getStatsFor("THIS_MONTH");
var statsSeven = account.getStatsFor("LAST_7_DAYS");
monthObj = statsMonth.getCost();
var seven = statsSeven.getCost();
sevenObj = seven / 7;
progObj = ((seven * dagarPrognos) + monthObj);
accountArr.push({"name": nameObj, "month": monthObj, "seven": sevenObj, "prognos": progObj});
}
return{account: accountArr};
}
My objective is to output the contents of the array "accountArray" individually as rows on the spreadsheet.