In a Google sheet, I have a custom form based off of some posts/blogs that I have found online to learn more about Google App Scripts. The form works correctly but I am having trouble with the column that should be creating an ID for the row.
From my reading, it seems that my problem is that math.max() takes a list not an array. Furthermore, none of the methods that I found for regular Javascript seem to be working in Google Apps Scripts. Such as, math.max.apply(null,array).
Do I have to iterate the array or is there something to make max() take an array?
Here is the code that I have been playing with.
function itemAdd(form) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var sh = SpreadsheetApp.getActiveSheet();
var lRow = sh.getLastRow();
var range = sh.getRange(3,1,lRow,1);
var maxNum = Math.max(range)
sheet.appendRow([maxNum,form.category, form.item, form.manupub,
form.details, form.quantity]);
return true;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…