Getting “This operation is not supported from a callback function” error when transposing array

Viewed 1177

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?

1 Answers
Related