Reputation: 27
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 completed 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");
}
Upvotes: 1
Views: 10175
Reputation: 346
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 ()
Upvotes: 4