Search code examples
google-apps-scriptgoogle-drive-apigoogle-docsgoogle-forms

replaceText working in one instance but not in another


The script is triggered when a Google form is submitted and then auto-fills a Google doc.

It worked perfectly before I added var servicesPTY = e.values[117]; and replaced all the placeholders perfectly. But as soon as I add it then the executions indicator show completed but no documents are produced anymore. The document has placeholders that look like this: {{servicesPTY}} {{regNumberPTY}} {{tradingNamePTY}}

And the code looks like this:

function myFormSubmitPTY(e) {

  var regNumberPTY = e.values[112];
  var taxNumberPTY = e.values[111];
  var tradingNamePTY = e.values[113];
  var servicesPTY = e.values[117];

var file = DriveApp.getFileById("16OwyBIZAD2pwkuUXZnYSj-9WB6ObGGRXiEjDLa1tcjw");

  var folder = DriveApp.getFolderById("1kogpJdxHLwuEhbVyh2oiIgTPH0SNac2m");

  var copy = file.makeCopy(tradingNamePTY, folder);

  var doc = DocumentApp.openById(copy.getId());

  var body = doc.getBody();

  if (type == "PTY (LTD)") {

  body.replaceText("{{servicesPTY}}",servicesPTY);
  body.replaceText("{{regNumberPTY}}", regNumberPTY);
  body.replaceText("{{tradingNamePTY}}", tradingNamePTY);


  doc.saveAndClose();
  }
}

Solution

  • I must have deselected the trigger for PTY. When I looked at the stackdriver logs I noticed PTY had none. Must have happened in the early hours of the morning. Thanks though. You guys put me on the right track