google apps script - Set the name of the document when it is created -


i trying edit "generate template" script. script based on template inputs information spreadsheet document. how works except names document copy of template row number. isn't efficient trying use for. question how able 1 of these options:

a: have name based on cell in row. example, there column named claim # , department. both of make title each document. document be: " {department name} {claim #} " based on information in column in row exported.

b: have box put in when generating document asks want file named.

thank help!

ps: if needed columns use name of document are: column e column d.

this code: (i did not make this, found in gallery.)

function generatedocument(e) {   var template = docslist.getfilebyid(e.parameter.templates);   var row = e.parameter.row   var mydocid = template.makecopy(template.getname()+" - "+ row).getid();   var mydoc = documentapp.openbyid(mydocid);   var copybody = mydoc.getactivesection();   var sheet = spreadsheetapp.getactivespreadsheet();   //browser.msgbox(row);   var myrow = spreadsheetapp.getactivespreadsheet().getrange(row+":"+row);   (var i=1;i<sheet.getlastcolumn()+1;i++){     var mycell = myrow.getcell(1, i);     copybody.replacetext("{"+mycell.geta1notation().replace(row,"")+"}", mycell.getvalue());   }   mydoc.saveandclose();   //var pdf = docslist.getfilebyid(copyid).getas("application/pdf");    //mailapp.sendemail(email_address, subject, body, {cc: carboncopy, name: sendername, htmlbody: body, attachments: pdf});     var app = uiapp.getactiveapplication();   app.close();   return app;  }  function gettemplates() {   var doc = spreadsheetapp.getactivespreadsheet();   var app = uiapp.createapplication().settitle('generate template');   // create grid 3 text boxes , corresponding labels   var grid = app.creategrid(3, 2);   grid.setwidget(0, 0, app.createlabel('template name:'));    var list = app.createlistbox();   list.setname('templates');   grid.setwidget(0, 1, list);   var docs = docslist.getfolder("templates").getfilesbytype("document");   (var = 0; < docs.length; i++) {     list.additem(docs[i].getname(),docs[i].getid());   }   grid.setwidget(1, 0, app.createlabel('row:'));   var row = app.createtextbox().setname('row');   row.setvalue(spreadsheetapp.getactivespreadsheet().getactiverange().getrow());   grid.setwidget(1, 1, row);   // create vertical panel..   var panel = app.createverticalpanel();    // ...and add grid panel   panel.add(grid);    // create button , click handler; pass in grid object callback element , handler click handler   // identify function b server click handler    var button = app.createbutton('submit');   var handler = app.createserverclickhandler('generatedocument');   handler.addcallbackelement(grid);   button.addclickhandler(handler);    // add button panel , panel application, display application app in spreadsheet doc   panel.add(button);   app.add(panel);   doc.show(app); }  function onopen() {      var ss = spreadsheetapp.getactivespreadsheet();   var menuentries = [{name: "generate template", functionname: "gettemplates"}];     ss.addmenu("template generator", menuentries);   } 

the makecopy method includes possibility give name copy, autocomplete shows clearly

enter image description here in code :

function generatedocument(e) {   var template = docslist.getfilebyid(e.parameter.templates);   var sheet = spreadsheetapp.getactivespreadsheet();// moved line bit have sheet available    var row = e.parameter.row   var mydocid = template.makecopy(sheet.getrange('e'+row).getvalue()+'-'+sheet.getrange('d'+row).getvalue()).getid();// basic implementation compose name content of column d , e separated hyphen... customize way want.   ... 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -