I have the following apps script, which copies a Google Docs file and inserts some values to it which it gets from a spreadsheet file.
function AutomatischAusfuellen(e) {
var Zeitstempel = e.values[0];
var Vorname = e.values[1];
var Nachname = e.values[2];
var Strasse = e.values[3];
var Hausnummer = e.values[4];
var Postleitzahl = e.values[5];
var GemeindeOderStadt = e.values[6];
var Betreff = e.values[7];
var Nachricht = e.values[8];
var Datum = Zeitstempel.slice(0, -9);
var Dokument = DocumentApp.openById(DriveApp.getFileById('####').makeCopy(Zeitstempel + ' - ' + Betreff + ' - ' + Vorname + ' ' + Nachname, DriveApp.getFolderById('####')).getId());
var Ausfuellen = Dokument.getBody().replaceText;
Ausfuellen('{{Vorname}}', Vorname);
Ausfuellen('{{Nachname}}', Nachname);
Ausfuellen('{{Straße}}', Strasse);
Ausfuellen('{{Hausnummer}}', Hausnummer);
Ausfuellen('{{Postleitzahl}}', Postleitzahl);
Ausfuellen('{{Gemeinde oder Stadt}}', GemeindeOderStadt);
Ausfuellen('{{Betreff}}', Betreff);
Ausfuellen('{{Nachricht}}', Nachricht);
Ausfuellen('{{Datum}}', Datum);
Dokument.saveAndClose();
}
Sorry for this (probably) messy and uncommented code. I know I definitely need to put more attention to things like this. It works perfectly right now, but there are 2 things I want to change. At first, the file needs to be saved as a pdf instead of a Google Docs file. The second thing is that the file should be saved in the root of my GDrive. It would be really great if someone could help me out as I've never worked with JavaScript or Google Apps Script before. :)