I have a function for web applications that can copy templates. It receives the name of the template and the id of the template as parameters.
code.gs
Function generate_(idTemplate, name) {
var template = DriveApp.getFileById(idTemplate); var folder = '文件夹id'; var copyName = name + "-" + CurrentDate;// 添加创建日期 var copy; try { copy = template.makeCopy(copyName, folder); } catch (e) { Logger.log(e.stack); } var nameF = copy.getName(); var linkF = copy.getUrl() Logger.log(nameF,linkF) return getFile(nameF,linkF) // 这些值是我想要传递给客户端的。 }
This function is what I use to pass the copied name and URL to the client. I know that in JavaScript, to return multiple parameters, it must be implemented through an array.
function getFile(nameF,linkF){ var array = [nameF,linkF]; return array; }
This is the client script I'm using to try to retrieve the generated replicated data:
HTML
I use a button to test whether it is passed correctly, but I cannot display the data, the browser console shows null when displaying the log.
What could I have done wrong? On the client side I've triedgoogle.script.run.withSuccessHandler(copyValues).getFile(nameF,linkF);
but it didn't work.
Try this:
GS:
HTML:
Dialog:
This is an example of getting file information.
As shown in the screenshot below, when I click the button, the file name and URL will be displayed in the input box.
Code.gs
HTML_Test.html