javascript - A google spreadsheet script that triggers on edit of a column in a sheet and overwrites the value of a user defined cell or not depending on the value -
hope well.
i trying write nice script office because colleagues lack bit of discipline.
this script should trigger if column in sheet edited, preferably, it's fine if trigger on sheet edit or maybe on spreadsheet edit. script should @ value in column of sheet , if of them have strings "on hold(i)","on hold(ii)" or "on hold(iii)" cell on column (chosen user) on same row should overwritten string "tbc". tried piecing google , below got since here doesn't work haha. appreciated !! :((
function onedit() { var a=1; var ss = spreadsheetapp.getactivespreadsheet(); while ( a<200 ){ if ( ss.getsheetbyname('active jobs').getrange(a,12) == "on hold (i)" ) { ss.getsheetbyname('active jobs').getrange(a,15).setvalues("tbc"); a=a+1; } } }
i read somewhere on google naming funciton onedit make function trigger if spreadsheet edited doesn't seem work.
function onedit() { var a=1; var ss = spreadsheetapp.getactivespreadsheet(); var activesheet = ss.getactivesheet(); var activecell = activesheet.getactivecell(); //check if sheet job sheet , cell status cell if (activesheet.getname().indexof("job id") != -1 && activecell.getrow() == 2 && activecell.getcolumn() == 15){ var switchvalue = activecell.getvalue(); switch (switchvalue){ case "on hold (i)": case "on hold (ii)": case "on hold (iii)": case "to assigned": //write date active jobs sheet adddatetoactive("tbc"); break; case "in progress": var newdate = browser.inputbox("please enter report out date"); adddatetoactive(newdate); break; default: browser.msgbox("gothere"); } } } function adddatetoactive(input){ var ss = spreadsheetapp.getactivespreadsheet(); var activesheet = ss.getactivesheet(); var activecell = activesheet.getactivecell(); var jobid = activesheet.getrange(2,1).getvalue().tostring(); var activejobsheet = ss.getsheetbyname("active jobs"); var activejobs = activejobsheet.getrange(1,1,activejobsheet.getlastrow(),1).getvalues(); activejobs = columntoarray(activejobs); var jobrow = activejobs.indexof(jobid)+1; if (jobrow == -1){ browser.msgbox("job id not preent on active jobs sheet"); }else{ activejobsheet.getrange(jobrow,15).setvalue(input); } } function columntoarray(columndata){ //ensure data supplied column if(columndata[0].length == 1){ //convert column array var dataout = []; (var = 0; < columndata.length; a++){ dataout.push(columndata[a][0]); } }else{ throw new error("data supplied columntoarray not simple column"); } return dataout; }
Comments
Post a Comment