我创建了一个脚本,允许我列出并更新我有权访问的所有Google Analytics媒体资源。 我想做的是存储每个循环结果(例如:属性A已更新;属性B已更新等)并返回脚本末尾的所有结果。
目前我的脚本看起来像这样:
var output = [];
function menuItem1() {
var ui = SpreadsheetApp.getUi();
var response = ui.alert('Are you sure you want to generate a list of all the properties ?', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response == ui.Button.YES) {
function showOutput() {
var html = HtmlService.createHtmlOutputFromFile('output');
var ui = SpreadsheetApp.getUi();
ui.showModalDialog(html, 'Results');
}
function getProperties() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Overview');
var accounts = Analytics.Management.Accounts.list().items;
accounts.forEach(function(account) {
var webProperties = Analytics.Management.Webproperties.list(account.id).items;
webProperties.forEach(function(webProperty) {
var results = [
webProperty.accountId,
webProperty.id,
webProperty.name,
webProperty.websiteUrl,
webProperty.dataRetentionTtl,
webProperty.dataRetentionResetOnNewActivity
];
output.push('Property ' + webProperty.id + ' has been listed.');
sheet.appendRow(results);
});
});
}
getProperties();
showOutput();
}
}
我的HTML文件如下所示:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<table>
<? for (var i = 0; i < output.length; i++) { ?>
<tr>
<?= output[i] ?>
</tr>
<? } ?>
</table>
</body>
</html>
当我在getProperties()函数之后执行Logger.log(输出)时,我确实得到了所有结果。但是现在我想在模态对话框上打印输出,它不起作用。该框仅显示HTML代码。
对我做错了什么的想法?
谢谢