0

I am creating a Google Script to poll data from a spreadsheet (full code in the question here) and am getting this error when the google script is called: Uncaught Error: The script completed but the returned value is not a supported return type. The google script is trying to return a 2D array - how can I fix the function so that it successfully passes the 2D array back to the next Javascript function?

function handleFormSubmit() {
    var formObject = document.getElementById('text').value;
    google.script.run.withSuccessHandler(createTable).getSportData(formObject);
  }

 /**
 * Adds an html table
 */ 
 function createTable(tableData) {
  console.log("The tableData for createTable() is " + tableData);
  var table = document.createElement('table');
  var tableBody = document.createElement('tbody');

tableData.forEach(function(rowData) {
  var row = document.createElement('tr');

  rowData.forEach(function(cellData) {
    var cell = document.createElement('td');
    cell.appendChild(document.createTextNode(cellData));
    row.appendChild(cell);
  });

  tableBody.appendChild(row);
});

table.appendChild(tableBody);
document.body.appendChild(table);
}
Community
  • 1
  • 1
Grant
  • 131
  • 1
  • 2
  • 12
  • Have you checked to see that your formObject variable is what you are expecting? It looks to me like it will be a single value, not an array. If you are collecting the entire form object in this way it's not a pattern I've seen before! – Sam Scholefield Nov 24 '16 at 14:16
  • neither of these functions has a return statement – Robin Gertenbach Nov 24 '16 at 15:45
  • Try adding Logger.log to your getSportData function and make sure it is returning what you expect. – Jeremy Nov 24 '16 at 17:49
  • @RobinGertenbach The google.script.run call returns the output of `getSportData()` to `createTable()` - https://developers.google.com/apps-script/guides/html/reference/run – Sam Scholefield Nov 25 '16 at 11:47

1 Answers1

1

In your getSportData function return JSON.stringify(your2Darrayvar) instead of the actual array. Then in your createTable function use JSON.parse(data) to convert it back to proper 2D array.

azawaza
  • 3,065
  • 1
  • 17
  • 20