Tim Tim - 4 months ago 24
Javascript Question

Change Function from getActiveSheet() to getSheetByName("mySheet")

I am very new to Google scripts and am finding it a little confusing

The function

getdata
along with setting a timer will re-query the
ImportJSON
but the function only writes to the first sheet.

I need to set which sheet the function writes to.

I have tried:

SpreadsheetApp.getActiveSpreadsheet.getSheetByName("mySheet").getRange('A2').setValue(cellFunction);


but does not work.

Thanks!

function getData() {
var queryString = Math.random();
var cellFunction = '=ImportJSON("https://sum-app.net/json?key=Mg.Clxt6A.TV1DFtPA0k8Ehpb0RDxyLH7xhU8", "/elements", "noInherit,noTruncate,Headers?' + "," + queryString + '")';

SpreadsheetApp.getActiveSheet().getRange('A2').setValue(cellFunction);
}

Answer

In your first attempt, getActiveSpreadsheet should be getActiveSpreadsheet()