triggers - Copied value disappears when row that contained source value is deleted in Google spreadsheets -
i wrote script used trigger onedit in sheet. idea pick value worksheet, copy worksheet based on logic, , delete source row contained original value.
when run, times, copy take place, on delete, copied value disappear. 1 way noticed fixes problem if delete trigger, save, , create again...
how can avoid behavior?
function onedit(e) { var range = e.range; var entry = range.getsheet(); var sss = entry.getparent(); if (sss.getname() != "weight tracker") return; if (entry.getname() != "entry") return; logger.log("copydata running...."+range.getcell(1,2).getvalue()); var weight = range.getcell(1,2).getvalue(); logger.log("weight = "+weight); var details = sss.getsheetbyname('details'); var trange = details.getrange(3, 1, 200); var data = trange.getvalues(); var today = new date().sethours(0,0,0,0); for(var n=0;n<data.length;n++) { var date = new date(data[n]).sethours(0,0,0,0); logger.log("date = "+date+" =? "+today); if(date == today) { break }; } logger.log("n = "+n+" today: "+today); // n 0 based, sheet 1 based + 2 headers = 3, 5 jim's weight details.getrange(n+3,5).setvalue(weight); // rid of row next addition arrives top row logger.log("deleting row..."); // reason deleting road removes value entered... range.getsheet().deleterow(1); }
Comments
Post a Comment