We're migrating our users to a portal and are closing our personalized Google forms so that our users stop using them and go to the portal. I need to mass update them through apps script. There's script that allows me to batch update and close and I found some in Google's resources that will allow me to put a message in the description telling them where to go. So I set that script up and sent it to run in a folder and all of it's subfolders - I really only want to update the forms that are in my active users folder. I don't need to update all our forms, there are some that cannot be updated since we are not migrating those users just yet, and there are many that are closed accounts already that don't need to be updated so I'm leaving them out of it. So I have it set to this specific folder- and when I debug or run it, it keeps giving me an error that the folder isn't defined, when it's been defined in many, many attempts and different versions of the script. Before you ask, yes I already have DriveApp (Drive API now) on the script.
Is there anyone who can help me stop getting this error?
I have tried several versions of the script to get a sample form to work as planned to make sure the rest will work. I have tried running it with the folderID, with the folderTitle/folderName, I've tried with and with out Drive API. I have checked and re-checked that my form title and folder ID or title are correct, etc. I've also checked to see that the folder was defined, and that the driveapp was defined. Nothing has been missed that I'm aware of. But I'm still really new to all of this. so thanks in advance for your help.
Here is the latest version (of many) redacted version of my script that's just to check one form first. please enter your own folder and form information to test it out? Sorry!
UPDATED to add the exact error I get when running the script:
ReferenceError: folder is not defined
function closeSpecificFormInFolder() {
var folderId = "Your Folder ID";
var formTitle = "Your Form Here";
var message = "This form is now closed. Please visit https://stackoverflow.com for further instructions.";
// Get the DriveApp service after it has been loaded
var driveApp = ScriptApp.getService('DriveAPI');
// Get the folder using the driveApp service
var folder = driveApp.getFolderById(folderId);
var files = folder.getFiles();
while (files.hasNext()) {
var file = files.next();
var form = FormApp.openById(file.getId());
if (form.getTitle() === formTitle) {
// Close the form
form.setAcceptingResponses(false);
// Add your message to the description of the form
form.setDescription(message);
Logger.log("Closed and updated form: " + formTitle);
return;
}
}
Logger.log("Form not found: " + formTitle);
}
again, thanks in advance for your kind help. newbie here.