3

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?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Shortcake
  • 31
  • 3
  • You are using the debug tool, right? Regarding asking for help for debugging code, take a look to [mcve], and take a look to http://stackoverflow.com/questions/32619480/debugger-fails-with-this-operation-is-not-supported-from-a-callback-function – Rubén Mar 10 '16 at 16:56
  • yes it appears i had was not allowed a breakpoint in the debugger at that point and the code actually works well. – Shortcake Mar 10 '16 at 17:12

1 Answers1

3

Answer

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.

References

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."

Community
  • 1
  • 1
Rubén
  • 34,714
  • 9
  • 70
  • 166