javascript - GAS Spreadsheet avoid getting duplicates by marking as "SENT", not working? -
i have script in google spreadsheet , fetches rows marked "ready" fine, sets value in column "w"(23) "sent", , trying avoid fetching duplicates, marking column "sent" when run code again, ignores "sent" pasted? wrong here?
var ss = spreadsheetapp.openbyid("12y85gmj94s6k3213j2ngk8rfr0gofd_emfk8whu_muq"); var stitchsheet = ss.getsheetbyname("sheet8"); var ordersheet = ss.getsheetbyname("sheet1"); var sent = "sent"; function getorders() { var range = ordersheet.getdatarange(); var orders = range.getvalues(); (var = 1; < orders.length; i++) { var row = orders[i]; var status = row[1]; var order = row[4]; var name = row[5]; var system = row[22]; if(system != sent){ if(status.tostring() === 'ready'){ ordersheet.getrange(i,23).setvalue(sent); stitchsheet.appendrow([order,name]); } } } }
your code fine, there must logical error somewhere. i've noticed made var i
in loop 1
. not know if intentional or not, index of arrays pretty starts 0 in programming languages, means you'll start @ row 2 of sheet, not row 1.
finding logical errors
to find logical errors need learn how use debugger console in script editor.
put breakpoints on lines mark star below:
var ss = spreadsheetapp.openbyid("12y85gmj94s6k3213j2ngk8rfr0gofd_emfk8whu_muq"); var stitchsheet = ss.getsheetbyname("sheet8"); var ordersheet = ss.getsheetbyname("sheet1"); var sent = "sent"; function getorders() { var range = ordersheet.getdatarange(); * var orders = range.getvalues(); (var = 1; < orders.length; i++) { * var row = orders[i]; var status = row[1]; var order = row[4]; var name = row[5]; * var system = row[22]; if(system != sent){ if(status.tostring() === 'ready'){ ordersheet.getrange(i,23).setvalue(sent); stitchsheet.appendrow([order,name]); } } } }
start debugger , stop @ first breakpoint. inspect value range
has. expanding this
should let find ordersheet
, sent
(since outside function , should in scope). if not you've got problem here.
go next breakpoint , inspect orders
, should have array of arrays now. can inspect you've got right values, if not, skip forward next breakpoint , @ row
is.
Comments
Post a Comment