This problem has me wanting to pull my hair out. I am trying to pass a URL parameter to Google Apps Script containing the row ID (from a spreadsheet) for the data I'm wanting to present. My parameter is story. However, I'm getting all sorts of errors no matter what I try. The latest being:
TypeError: Cannot read property "parameter" from undefined. (line 2, file "Code", project "singleStory")
Below are my Code.gs and Index.html files (The project is not complete. This is just where I'm at so far.)
Code.gs
function doGet(e) {
var i = e.parameter.story;
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
function getData() {
return SpreadsheetApp
.openById("1Z582cnr03fkLC7xCca4pcj7QwDtSCS4KGneyFKMgdyo")
.getSheetByName("StoryTopics")
.getDataRange()
.getValues();
}
}
Index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<? var data = doGet(); ?>
<div id="container">
<div id="header">
<div id="topicname">
<?= data[i][0] ?>
</div>
<div id="todaysdate">
<p>As of: <?= new Date() ?></p>
</div>
<div id="topictype">
<?= data[i][1] ?>
</div>
<div id="locale">
<?= data[i][2] ?>
</div>
</div>
<div id="contact_container">
<div id="subheader">
</div>
<div id="contact_name">
<?= data[i][3] ?>
</div>
<div id="contact_title">
<?= data[i][4] ?>, <?= data[i][5] ?>
</div>
<div id="contact_email">
<?= data[i][6] ?>
</div>
<div id="contact_phone">
<?= data[i][7] ?>
</div>
</div>
<div id="action_container">
<div id="subheader">
</div>
<table id="action_table">
<tr>
<td>
Date:
</td>
<td>
Type:
</td>
<td>
Description:
</td>
</tr>
</table>
</div>
<div id="story_container">
<div id="story_title">
</div>
<div id="story_content">
</div>
</div>
</div>
</body>
</html>
The URL + parameter I'm using to test is:
https://script.google.com/a/macros/--DOMAIN--/s/--SCRIPTID--/exec?story=3
Can anyone give me some ideas on why it's not working?
ebeing passed intodoGet()? I am not familiar with this way of calling AppScript functions, but it looks like the parameter is missing in your index.htmldoGet()- the HTML is being generated by that function, so you're setting up an execution loop. The second invocation has no event parameter, so BOOM.)