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);
}
4
  • 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! Commented Nov 24, 2016 at 14:16
  • neither of these functions has a return statement Commented Nov 24, 2016 at 15:45
  • Try adding Logger.log to your getSportData function and make sure it is returning what you expect. Commented Nov 24, 2016 at 17:49
  • @RobinGertenbach The google.script.run call returns the output of getSportData() to createTable() - developers.google.com/apps-script/guides/html/reference/run Commented Nov 25, 2016 at 11:47

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.