google apps script - TimeStamp Updates to Adjacent Columns -


i've wondering if possible , how go it. google sheets. here script i'm using (found script , edited use):

function onedit(e) { var s = e.source.getactivesheet().getname(); var cols = [5]; if (s !== 'michele' && s !== 'janet' && s !== 'stephanie' || cols.indexof(e.range.columnstart) ==-1 || !e.value) return;   e.range.offset(0,1).setvalue(utilities.formatdate(new date(), "cst", "mm/dd/yyyy hh:mm:ss")); } 

column 5 (e) has option choose different statuses. far, have putting timestamp of column 5's change in adjacent column, 6 (f). i'm trying figure out if status changed again (pending -> confirmed-> installed-> ect) , instead of updating column 6, timestamped, instead move on column 7, 8, 9, ect.

let me know if more detail needed.

thanks bunch!

i've tested code , works. finds number of cells right of column e have values in them, , calculates next empty column is, , writes new date next empty column.

function onedit(e) {   var sh = e.source.getactivesheet();   var s = sh.getname();   var lastcol = sh.getlastcolumn();    var cols = [5];   var startcol = spreadsheetapp.getactivespreadsheet().getrangebyname('columne').getcolumn();   //in spreadsheet, name range in column want start @   if (s !== 'michele' && s !== 'janet' && s !== 'stephanie' || cols.indexof(e.range.columnstart) ==-1 || !e.value) return;    var rowedited = e.range.getrow(); //get row edited   //start in row edited , column 6, 1 row , x columns   var datesincells = sh.getrange(rowedited,startcol,1,lastcol - 5).getvalues();    logger.log('datesincells: ' + datesincells);   logger.log('datesincells.length: ' + datesincells[0].length);    var numberofdates = 0;    (var i=0;i<datesincells[0].length;i+=1) {     if (datesincells[0][i] !== "") {       numberofdates +=1;     };   };    logger.log('numberofdates: ' + numberofdates);    var coltowriteto = startcol + numberofdates;   var newdate = utilities.formatdate(new date(), "cst", "mm/dd/yyyy hh:mm:ss");   //var thestatus = sh.getrange(rowedited, 5).getvalue();   var thestatus = e.value;   var bothstatusanddate = newdate + " : " + thestatus;    sh.getrange(rowedited,coltowriteto).setvalue(bothstatusanddate); }; 

version two:

function onedit(e) {   var sh = e.source.getactivesheet();   var s = sh.getname();   var lastcol = sh.getlastcolumn();    var cols = [5];    if (s !== 'michele' && s !== 'janet' && s !== 'stephanie' || cols.indexof(e.range.columnstart) ==-1 || !e.value) return;    var rowedited = e.range.getrow(); //get row edited   //start in row edited , column 6, 1 row , x columns   var datesincells = sh.getrange(rowedited,6,1,lastcol - 5).getvalues();    logger.log('datesincells: ' + datesincells);   logger.log('datesincells.length: ' + datesincells[0].length);    var numberofdates = 0;    (var i=0;i<datesincells[0].length;i+=1) {     if (datesincells[0][i] !== "") {       numberofdates +=1;     };   };    logger.log('numberofdates: ' + numberofdates);   var newdate = utilities.formatdate(new date(), "cst", "mm/dd/yyyy hh:mm:ss");   if (numberofdates > 4) {     var existingvalues = sh.getrange(rowedited,7,1,4).getvalues();     sh.getrange(rowedited,6,1,4).setvalues(existingvalues);     sh.getrange(rowedited,10).setvalue(newdate);     return;   };    var coltowriteto = 6 + numberofdates;    sh.getrange(rowedited,coltowriteto).setvalue(newdate); }; 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -