return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - is not a function error in Google Apps Script - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - is not a function error in Google Apps Script - Stack Overflow

programmeradmin2浏览0评论

I'm continuing to have trouble with the following google app-script. Right now it is surfacing on the ranger.activate() line. When run the following error shows up in my log:

[20-06-20 08:16:26:262 PDT] TypeError: ranger.activate is not a function at createDocFromRow(Code:14:8)

What this code is trying to do is take a selected row in a Google Sheet and turn it into a data object (this happens in more steps than is needed, but I'm breaking it down granularly to try and find the problem. Once found i can amalgamate steps and reduce VAR calls).

Once the data object is created, I parse out the data I need and drop it into a Google Doc template.

Any help identifying the root cause of this "is not a function" error would go a long way to my mental health improvement.

function createDocFromRow(){
var templateid = "1UjKBk0SyNUlswiWxXm3oCpEg3-RsJCPhTwwnyjif58s"; // Label Copy Doc ID
var FOLDER_NAME = "Label Copy"; // folder name of where to put pleted Docs
var FILENAME = "LabelCopy" // To save new files as
// get the data from a ROW selected by Spreadsheet user
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var ranger = sheet.getSelection().getActiveRange;
ranger.activate();
ss.toast(ranger);
var dataArray = ranger.getValues();
// dataArray is my object[][]
var songname = dataArray[0][2];
var songwriters = dataArray[0][3];
var publishers =  dataArray[0][4];
var artist = dataArray[0][6];
var useremail = dataArray[0][7];
// create a new Label Copy Document 
var docid = DocsList.getFileById(templateid).makeCopy().getId();
var doc = DocumentApp.openById(docid);
var body = doc.getActiveSection();
// replace text FROM dataArray into placeholder space
body.replaceText("##SONG NAME##", songname);
body.replaceText("##artist##", artist);
body.replaceText("##user email##", useremail);
body.replaceText("##Timestamp##", Utilities.formatDate(row[1], "GMT", "HH:mm dd/MM/yyyy"));
body.replaceText("##Songwriters##", songwriters);
body.replaceText("##Publishers##", publishers);
//Prepare to close and rename file.
var folder = DocsList.getFolder(FOLDER_NAME);
file.addToFolder(folder);
doc.setName(LABELCOPY+artists)
doc.saveAndClose();
// message Sheets user
ss.toast("Label Copy Document Created");
}

I'm continuing to have trouble with the following google app-script. Right now it is surfacing on the ranger.activate() line. When run the following error shows up in my log:

[20-06-20 08:16:26:262 PDT] TypeError: ranger.activate is not a function at createDocFromRow(Code:14:8)

What this code is trying to do is take a selected row in a Google Sheet and turn it into a data object (this happens in more steps than is needed, but I'm breaking it down granularly to try and find the problem. Once found i can amalgamate steps and reduce VAR calls).

Once the data object is created, I parse out the data I need and drop it into a Google Doc template.

Any help identifying the root cause of this "is not a function" error would go a long way to my mental health improvement.

function createDocFromRow(){
var templateid = "1UjKBk0SyNUlswiWxXm3oCpEg3-RsJCPhTwwnyjif58s"; // Label Copy Doc ID
var FOLDER_NAME = "Label Copy"; // folder name of where to put pleted Docs
var FILENAME = "LabelCopy" // To save new files as
// get the data from a ROW selected by Spreadsheet user
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var ranger = sheet.getSelection().getActiveRange;
ranger.activate();
ss.toast(ranger);
var dataArray = ranger.getValues();
// dataArray is my object[][]
var songname = dataArray[0][2];
var songwriters = dataArray[0][3];
var publishers =  dataArray[0][4];
var artist = dataArray[0][6];
var useremail = dataArray[0][7];
// create a new Label Copy Document 
var docid = DocsList.getFileById(templateid).makeCopy().getId();
var doc = DocumentApp.openById(docid);
var body = doc.getActiveSection();
// replace text FROM dataArray into placeholder space
body.replaceText("##SONG NAME##", songname);
body.replaceText("##artist##", artist);
body.replaceText("##user email##", useremail);
body.replaceText("##Timestamp##", Utilities.formatDate(row[1], "GMT", "HH:mm dd/MM/yyyy"));
body.replaceText("##Songwriters##", songwriters);
body.replaceText("##Publishers##", publishers);
//Prepare to close and rename file.
var folder = DocsList.getFolder(FOLDER_NAME);
file.addToFolder(folder);
doc.setName(LABELCOPY+artists)
doc.saveAndClose();
// message Sheets user
ss.toast("Label Copy Document Created");
}
Share Improve this question edited Oct 23, 2022 at 1:24 Wicket 38.7k9 gold badges80 silver badges195 bronze badges asked Jun 20, 2020 at 15:21 Ezra GreeneEzra Greene 271 gold badge1 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

It should be

var ranger = sheet.getSelection().getActiveRange();
ranger.activate();

You are missing () for getActiveRange

Explanation

getActiveRange is a Function which returns an instance of Range Class. And a function needs to be invoked using parentheses ()

发布评论

评论列表(0)

  1. 暂无评论