javascript - Google Apps Script - Using Sidebar form to append a row to spreadsheet -
this script should append new row spreadsheet 'onclick' of button, doesn't. want able add data each textbox corresponding column , append new row. not sure why doesn't work. how append new row? script works in script editor when run it, not in sidebar html.
// use code google docs, forms, or new sheets. function onopen() { spreadsheetapp.getui() // or documentapp or formapp. .createmenu('sidebar') .additem('open', 'opendialog') .addtoui(); } function opendialog() { var html = htmlservice.createhtmloutputfromfile("index"); html.settitle('gmf sent msg form'); spreadsheetapp.getui().showsidebar(html); } function insertrow(){ var doc = spreadsheetapp.openbyurl("https://docs.google.com/spreadsheets/d/1ry3tzvu- tfhlcyf9tkrk4hb4b6q1tnya5k7ixyktyky/edit#gid=0"); doc.getactivesheet().appendrow(['700','9/12/16','po 16-45789']) }
<body> use form enter information cells of spreadsheet.<br> <form> <p>id</p> <input type="text" name="txtid" /> <p>date</p> <input type="text" name="txtdate"/> <p>subject</p> <input type="text" name="txtsub" /> <input type="button" value="append row" onclick="google.script.run .withsuccesshandler(insertrow)" /> </form> </body>
at line:
<input type="button" value="append row" onclick="google.script.run.withsuccesshandler(insertrow)" />
you're setting callback function withsuccesshandler() you're not calling server-side function, call directly need use:
google.script.run.insertrow();
if want set callback function run if server-side function returns successfully.
google.script.run.withsuccesshandler(onsuccess).insertrow();
for more information, see guide of communicating server functions , google.script.run.
Comments
Post a Comment