From server to GAS: the path of data transfer
P粉141911244
P粉141911244 2023-09-18 23:38:40
0
2
484

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.

P粉141911244
P粉141911244

reply all (2)
P粉147045274

Try this:

GS:

function launchmydialog() { let t = HtmlService.createTemplateFromFile("ah2"); t.t1 = "one"; t.t2 = "two"; SpreadsheetApp.getUi().showModelessDialog(t.evaluate(),"Dialog"); }

HTML:

    


Dialog:

    P粉951914381

    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

    function showTest() { setFileInfo(); let html = HtmlService.createHtmlOutputFromFile("HTML_Test"); SpreadsheetApp.getUi().showModalDialog(html,"Test"); } function setFileInfo() { let id = "1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxE"; let name = "Copy of Template"; let template = DriveApp.getFileById(id); let copy = template.makeCopy(name); let properties = PropertiesService.getDocumentProperties(); let property = [copy.getName(),copy.getUrl()]; properties.setProperty("FileInfo",JSON.stringify(property)); } function getFileInfo() { let properties = PropertiesService.getDocumentProperties(); let property = properties.getProperty("FileInfo"); if( property ) { return JSON.parse(property); } return "Error"; }

    HTML_Test.html

       
    

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!