google apps script - Need to Set_Formula on Insert_Row from IFTTT -
novice google apps scripter here,
i have ifttt applet adds row spreadsheet via email: data test
i seem have formulas set correctly, when new row added, formulas not auto-populate new row. when row inserted, in corresponding cells in columns , b not blank, i'd set formulas in row.
the script have far (see below) give me formulas want, in row1. i'd script set same formulas corresponding cells of new row inserted.
for example, ifttt.com automation populate cells a6 , b6 text (i.e., next blank row in linked spreadsheet) -- need of formulas entered apply b6 (as opposed b2)
function myfunction() { var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheets()[0]; var cell = sheet.getrange("c1"); cell.setformula('=iferror(mid($b2,search("details",$b2)+7,search(",",$b2)-search("details",$b2)-7),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("d1"); cell.setformula('=iferror(trim(left(substitute(mid(b2,find("$",b2),len(b2))," ",rept(" ",100)),100)),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("e1"); cell.setformula('=iferror(mid($b2,search("exceed",$b2)+7,search("%",$b2)-search("exceed",$b2)-6),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("f1"); cell.setformula('=iferror(mid($b2,search("due",$b2)+3,search(";",$b2)-search("due",$b2)-3),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("g1"); cell.setformula('=iferror(mid($b2,search("held on",$b2)+7,search(". lottery",$b2)-search("held on",$b2)-7),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("h1"); cell.setformula('=iferror(mid($b2,search("posted by",$b2)+9,search(". ",$b2)-search("",$b2)-167),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); } any assistance appreciated!
try out:
var ss = spreadsheetapp.getactivespreadsheet(); function onopen() { var items = [ {name: 'add row', functionname: 'addrow'}, ]; ss.addmenu('add row', items); } function addrow() { var ui = spreadsheetapp.getui(); var ss = spreadsheetapp.getactivespreadsheet(); var sheet = ss.getsheets()[0]; var result = ui.prompt( 'enter number of row', ui.buttonset.ok_cancel); // process user's response. var button = result.getselectedbutton(); var rownum = result.getresponsetext(); if (button == ui.button.ok) { // user clicked "ok". sheet.insertrowafter(rownum); var cell = sheet.getrange("c" + rownum); cell.setformula('=iferror(mid($b' + rownum +',search("details",$b' + rownum +')+7,search(",",$b' + rownum +')-search("details",$b' + rownum +')-7),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("d" + rownum); cell.setformula('=iferror(trim(left(substitute(mid(b' + rownum +',find("$",b' + rownum +'),len(b' + rownum +'))," ",rept(" ",100)),100)),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("e" + rownum); cell.setformula('=iferror(mid($b' + rownum +',search("exceed",$b' + rownum +')+7,search("%",$b' + rownum +')-search("exceed",$b' + rownum +')-6),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("f" + rownum); cell.setformula('=iferror(mid($b' + rownum +',search("due",$b' + rownum +')+3,search(";",$b' + rownum +')-search("due",$b' + rownum +')-3),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("g" + rownum); cell.setformula('=iferror(mid($b' + rownum +',search("held on",$b' + rownum +')+7,search(". lottery",$b' + rownum +')-search("held on",$b' + rownum +')-7),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); var cell = sheet.getrange("h" + rownum); cell.setformula('=iferror(mid($b' + rownum +',search("posted by",$b' + rownum +')+9,search(". ",$b' + rownum +')-search("",$b' + rownum +')-167),hyperlink("https://housing.sfgov.org/listings","see housing portal"))'); } else if (button == ui.button.cancel) { // user clicked "cancel". } else if (button == ui.button.close) { // user clicked x in title bar. } }
Comments
Post a Comment