First apologies for this question but GAS is a new syntax to me. I would like to do something that is simple in VBA syntax, but not in GAS.
I want to transpose one named range to another named range (e.g. from 4 rows to 4 columns) on different worksheets. There are examples on the web that use .getDataRange() but I wish to use a fixed named range, whether there is data contained within or not.
The syntax I am playing around with is the following:
var wksInput = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('New');
var wksDB = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Database');
var intDBNewRow = wksDB.getLastRow() + 1;
wksDB.getRange(intDBNewRow, wksDB.getRange('dbContacts').getColumn(), 1,wksDB.getRange('dbContacts').getNumColumns()).setValues(transposeRange(wksInput.getRange('frmVanContacts').getValues()));
Taking 4 rows from a fixed point on an input form worksheet (wksInput) to 4 columns on the last row of a recordset/database worksheet (wksDB)
Where transposeRange is:
function transposeRange(a)
{
return Object.keys(a[0]).map(function (c) { return a.map(function (r) { return r[c]; }); });
}
The error is:
This operation is not supported from a callback function.
What is wrong here?
The problem isn't with the transpose function, the problem is that the Google Apps Script debugger can't do step into callbacks by design, so when debugging your code, instead of doing a debug step into, put a breakpoint before and after the call of the transpose function in order to make the debugger to skip that call.
In Google Apps Script Issues there is a issue about this -> Issue 4662: Debug breakpoint within the function body of an Array.map() call causes a server error that has the following comment from a Googler
From https://code.google.com/p/google-apps-script-issues/issues/detail?id=4662#c3
This is currently working as intended -- we do not support debugger breakpoints withing callback functions. This issue will therefore be marked as a Feature request.
A related question with no answers yet but with informative comments that help me to find the above reference
Debugger fails with "This operation is not supported from a callback function."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With