Reputation: 6004
I'm trying to get this demo Google Sheets Blog Demo to run. I followed all steps but got this error after running https://script.google.com/macros/s/[spreadsheetID]/exec?key=abcdef
:
TypeError: undefined is not a function (line 19, file "Code")
Line 19 = var headings = rows[0].map(String.toLowerCase);
Below is the related function and here the full code.
function doGet(e) {
if (!isAuthorized(e)) {
return buildErrorResponse('not authorized');
}
var options = {
page: getPageParam(e),
category: getCategoryParam(e)
}
var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
var worksheet = spreadsheet.getSheets()[0];
var rows = worksheet.getDataRange().sort({column: 2, ascending: false}).getValues();
var headings = rows[0].map(String.toLowerCase);
var posts = rows.slice(1);
var postsWithHeadings = addHeadings(posts, headings);
var postsPublic = removeDrafts(postsWithHeadings);
var postsFiltered = filter(postsPublic, options.category);
var paginated = paginate(postsFiltered, options.page);
return buildSuccessResponse(paginated.posts, paginated.pages);
}
How to fix this issue?
Upvotes: 0
Views: 1145
Reputation: 201603
When I saw the full script at the GitHub, it was found that that script had published 2 years ago. In this case, V8 had not been added. In order to avoid the error of TypeError: undefined is not a function (line 19, file "Code")
, how about the following 2 patterns?
In this pattern, the script is used without V8 runtime. In this case, please disable V8 runtime at the script editor. By this, var headings = rows[0].map(String.toLowerCase);
can be used without the error.
In this pattern, the script is used with V8 runtime. In this case, please enable V8 runtime at the script editor. And also, please modify the script as follows.
From:var headings = rows[0].map(String.toLowerCase);
To:
var headings = rows[0].map(Function.prototype.call, String.prototype.toLowerCase);
Upvotes: 3