0

I have a collection of Google App. scripts that I run as standalone apps., usually embedded into Google Sites. Yesterday I copied one of my functioning scripts and modified as I have done many times in the past but now the new scriptit does not run, it fails with a syntax error. Having stared at this extremely simple script for hours without a resolution I am thinking it may be a problem with Google, or some issue in my domain (Corp. domain).

function doGet() {
   var t = HtmlService.createTemplateFromFile('index');  
   var ss = SpreadsheetApp.openById('sheet_ID');
   var lrN = ss.getSheetByName('NCMR').getLastRow();

t.statArray = ss.getSheetByName('NCMR').getRange('Z3:Z'+lrN+'').getValues();

return t.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

snip from the execution transcript when I try to run:

[17-04-13 06:39:26:322 PDT] Sheet.getRange([Z3:Z23]) [0.072 seconds]
[17-04-13 06:39:26:381 PDT] Range.getValues() [0.058 seconds]
[17-04-13 06:39:26:382 PDT] Function.apply([[]]) [0 seconds]
[17-04-13 06:39:26:389 PDT] Execution failed: SyntaxError: Syntax error. (line 8, file "Code") [0.254 seconds total runtime]

Error from debugger:

We're sorry, a server error occurred. Please wait a bit and try again.

and then it has the following in the left hand pane of the debugger:

<Unknown file>null [0]
Code : doGet [8]

Any help or insight will be much appreciated. Apologies if this is a lay up and/or has already been answered.

EDIT to add html file:

index.html

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<base target="_top">
</head>
<body>
<center>
<table>
<tr><td><b> Id</b></td></tr>
<?= for (var i = 0; i < statArray.length; i++) { ?>
  <?= for (var j = 0; j < statArray[i].length; j++) { ?>
    <tr><td><?= statArray[i] ?></td>
  <?= } ?>
    </tr>
<?= } ?>
</table>
</center>
</body>
</html>
2
  • 2
    I believe there is a syntax error in HTML file when you try to evaluate it throws an error in line 8 or t.evaluate step. Could you share your HTML file? Commented Apr 13, 2017 at 15:02
  • @Jack Brown: Yep, you are a genius! It was right there starring me in the face the entire time, the printing scriplet in the HTML file was supposed to be standard notation (<? . . . ?>), lesson learned on willy-nilly copy and paste. However, I still need the printing scriplet for the actual array vars. THANKS! Commented Apr 13, 2017 at 15:20

2 Answers 2

3

For reference: The author of the question figured out the problem/syntax error

The reason for the error was a syntax error in a scriptlet used in the html i.e modify this:

<?= for (var i = 0; i < statArray.length; i++) { ?>

to a standard scriptlet tag

<? for (var i = 0; i < statArray.length; i++) { ?>

Html code should be the following:

<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<base target="_top">
</head>
<body>
<center>
<table>
<tr><td><b> Id</b></td></tr>
<? for (var i = 0; i < statArray.length; i++) { ?>
  <? for (var j = 0; j < statArray[i].length; j++) { ?>
    <tr><td><?= statArray[i] ?></td>
  <? } ?>
    </tr>
<? } ?>
</table>
</center>
</body>
</html> 
Sign up to request clarification or add additional context in comments.

Comments

-1

have you tried to use index.html

function doGet() {
   var t = HtmlService.createTemplateFromFile('index.html');  
   var ss = SpreadsheetApp.openById('sheet_ID');
   var lrN = ss.getSheetByName('NCMR').getLastRow();

t.statArray = ss.getSheetByName('NCMR').getRange('Z3:Z'+lrN+'').getValues();

return t.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

4 Comments

Thank you for your suggestion. Unfortunately I just tried adding the .html extension but it still fails :(
hum... can you supply your index.html file as well?
When I run your code with a blank index.html template I receive 0 errors. you might look into that.
Yep, it was the html file, thanks for your help and quick response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.