Desired Behaviour
Populate Google Sheet with array of arrays from a Javascript file.
// in js file (within google apps script project)
var aoa = [["row_01_val01", "row_01_val02", "row_01_val03"],
["row_02_val01", "row_02_val02", "row_02_val03"]]; // etc
google.script.run.withSuccessHandler(console.log("success")).populateSpreadsheet(aoa);
// in code.gs
// define target_range (ignore discrepancies between example values above)
var target_range = active_sheet.getRange(2, 1, 834, 20);
// set values of target_range
target_range.setValues(aoa);
Current Behaviour
// chrome developer tools (firefox/firebug not supported at work)
Uncaught Cannot convert Array to Object[][]
Question
I'm unable to post more specific code due to work restrictions (cannot access SO from work, or take code home, hence the pseudo code), but are there any common 'gotchas'
when it comes to passing an array of arrays from a Javascript file to Code.gs
for use in setValues()
?
What I've Tried
In the js file, console.log(typeof(aoa))
returns object
just before passing it to populateSpreadsheet()
within Code.gs
, and then Logger.log(aoa)
within populateSpreadsheet()
also returns object
Example:
var outer_array = [];
inner_array = [1,2,3];
outer_array.push(inner_array);
typeof(outer_array);
"object"
I've tried to refactor the code several times, but am wondering if there are any common gotchas like size constraints, quotas, or timeouts or some other 'quirk' I haven't considered?
This question and answer, for example, required the array of arrays to be reconstructed before passing it to setValues()
(I tried this but it didn't work in my instance):
https://stackoverflow.com/a/11066322/1063287
Another thing I considered is that I'm using splice()
(MDN reference) to add some values to the inner array's within Code.gs
, so I'm not sure if that somehow changes the type permissible to be passed to setValues()
?