Reputation: 5
I have a Google Form that's used as a weekly sign-up sheet. I need a form for each week of the year and my current workflow involves manually duplicating and renaming the form each week.
I'm attempting to use some automation to speed up this workflow and reduce the amount of manual work. I have the following Google Apps Script that I'm using that makes a copy of the original Form.
function duplicateForm() {
var templateformId = '1WsWb-VHK36Hm5YY5YaZaA14RdM2GhIujPwqmxiFDMk8';
var destFolder = DriveApp.getFolderById("1zWmCz9BaJwctdcCfutUsvAs1_qQhledk");
var file = DriveApp.getFileById(templateformId).makeCopy("Training Requests 2023", destFolder);
var fileId = file.getId()
}
Ideally I'm wanting to rename each new form with a week start date e.g.
And so on until it gets to the last Monday of the current year.
Does anyone know a way of achieving this?
Upvotes: 0
Views: 92
Reputation: 64120
Try this:
function duplicateForm() {
const destFolder = DriveApp.getFolderById("folderid");
const files = destFolder.getFilesByType(MimeType.GOOGLE_SHEETS);
let d = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM/dd/yyyy");
let found = false;
while (files.hasNext()) {
let file = files.next();
if (file.getName().includes(d)) {
found = true;
}
}
if (new Date().getDay() == 1 && !found) {
DriveApp.getFileById("formid").makeCopy(`Training Requests 2023 - ${d}`, destFolder);
}
}
function createduplicateTrigger() {
if(ScriptApp.getProjectTriggers().filter(t => t.getHandlerFunction() == "duplicateForm").length == 0) {
ScriptApp.newTrigger("duplicateForm").timeBased().everyDays(1).atHour(0).create();
}
}
Upvotes: 0