Document Merge with Google App Maker

前端 未结 1 1816
野的像风
野的像风 2020-12-18 16:48

I would like to integrate a document merge into a workflow which I created in Google App Maker. Whenever an input is submitted in a form, the answers should be merged into a

相关标签:
1条回答
  • 2020-12-18 17:20

    Put the following in your onAfterCreate event of your model:

    var templateId = 'your template ID';
    var filename = 'Document for Customer ' + record.ClientName + new Date();
    
    var copyFile = DriveApp.getFileById(templateId).makeCopy(filename);
    
    var copyDoc = DocumentApp.openById(copyFile.getId());
    var copyBody = copyDoc.getBody();
    var fields = app.metadata.models.Clients.fields;
    
    for (var i in fields) {
      var text = '<<' + fields[i].name + '>>';
      var data = record[fields[i].name];
      copyBody.replaceText(text, data);
    }
    
    copyDoc.saveAndClose();
    

    That should do it for you. See the pictures as to the template and created document.

    0 讨论(0)
提交回复
热议问题