user interface - Google apps script UI services to HTML services -


i try convert simple google apps script code below html services code. code below written deprecated google apps script ui services! can me html services example code in usecase?

// script deprecated ui-services // how create app html-services?!!!? //this script runs in google website. //it has 1 textobject , 1 button. //when button pressed value entered stored in spreadsheet  sskey = 'sheetkey....';    function doget(){    var app = uiapp.createapplication().settitle('myapp');    //create panels en grid   var mainpanel = app.createverticalpanel();   var vpanel1 = app.createverticalpanel().setid('vpanel2');   var grid = app.creategrid(4, 2).setid('mygrid');    //vpanel1 widgets   var namelabel = app.createlabel('name');   var nametextbox = app.createtextbox().setwidth('400px').setname('name').setid('name');   var submitbutton = app.createbutton('verstuur').setid('submitbutton');     grid.setwidget(0, 0, namelabel)     .setwidget(0, 1, nametextbox)      .setwidget(1, 1, submitbutton);    //set handlers en callbackelement   var handler = app.createserverclickhandler('insertinss');   handler.addcallbackelement(vpanel1);   submitbutton.addclickhandler(handler);     // build screen   vpanel1.add(grid);   app.add(vpanel1);    return app; }  function insertinss(e){   var app =uiapp.getactiveapplication();   var collecteddata = [new date(), e.parameter.name] ;    var ss = spreadsheetapp.openbyid(sskey);   var sheet = ss.getsheetbyname('contacts');   sheet.getrange(sheet.getlastrow()+1, 1, 1, collecteddata.length).setvalues([collecteddata]);    app.getelementbyid('submitbutton').setvisible(false);    //reset fields on screen   app.getelementbyid('name').settext("");    return app; } 

your ui output looks this:

ui output

create html file, , enter code:

testform.html

<div>   <div>       name: <input id='idnamefield' type='text'/>   </div>    <br/>    <input type='button' value='verstuur' onmouseup='rungooglescript()'/> </div>  <script>   function onsuccess(argreturnvalue) {     alert('was successful ' + argreturnvalue);     //reset fields on screen     document.getelementbyid('idnamefield').value = "";   }    function rungooglescript() {     console.log('rungooglescript ran!');      var inputvalue = document.getelementbyid('idnamefield').value;      google.script.run.withsuccesshandler(onsuccess)       .insertinss(inputvalue);   };  </script> 

copy follow code into:

code.gs

function doget() {    return htmlservice.createtemplatefromfile('testform')     .evaluate() // evaluate must come before setting native mode     .settitle('the name of page')     .setsandboxmode(htmlservice.sandboxmode.native); }; 

in seperate .gs file add code:

function insertinss(argpassedinname){   var sskey = 'sheetkey....';    var ss = spreadsheetapp.openbyid(sskey);   var sheet = ss.getsheetbyname('contacts');   sheet.getrange(sheet.getlastrow()+1, 1, 1, argpassedinname.length).setvalue(argpassedinname); } 

Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -