Apps script to append doc pages for mass direct mail

34 views Asked by At

I've wrote a script in google sheets that generates a list of customers membership expiry dates that are due to expire in the next 30 days. this list is generated each week. The goal is to write to these customers (direct mail) telling them their membership is due to expire.

I want to create 1 document that contains say 20 letters / pages for each customer thats been flagged as due to expire. That way for automation I am able to just print 1 document instead of opening 20 individual docs and printing.

I know how to create 20 individual letters using a letter template. I don't know how to merge those 20 into 1 document. or even better instead of merging at time of creating just do a for each loop that adds the customers details into the template and adds a new page for the next customers details using the same template.

Any advise or solution would be most appreciated.

data.forEach(function (row) {

    const template = DriveApp.getFileById("1234");
    const destFolder = DriveApp.getFolderById("ABC")

    const copy = template.makeCopy("letter", destFolder)
    const doc = DocumentApp.openById(copy.getId())
    const body = doc.getBody();

    body.replaceText('{(First Name)}', row[0]);
    body.replaceText('{(Last Name)}', row[1]);

    doc.saveAndClose();

    }

  });
0

There are 0 answers