I have a script that creates a new (and deletes the old) google document.

function copyTemplate() { var form1 = DriveApp.getFilesByName('Form for dentist').next(); formUrl = form1.getUrl(); var formSome = FormApp.openByUrl(formUrl); var copyOfFile = DriveApp.getFilesByName('statement_copy'); while (copyOfFile.hasNext()) { var file = copyOfFile.next(); DriveApp.removeFile(file); } newFile = DriveApp.getFilesByName('template').next().makeCopy('statement_copy'); urlNew = newFile.getUrl(); var docFile = DocumentApp.openByUrl(urlNew); formSome.setConfirmationMessage(urlNew); } 

But this script works for a very long time. And sometimes I need to send the data from the form directly to this file (which is being created). Is it possible to make it so that the form cannot be sent until the file is created on the disk?

    1 answer 1

    Operations on the server are performed sequentially. Therefore, if there is no error, then the file is already there. You can write anything in it.

    You can check the existence of a file at all only by catching an error.

     function test() { Logger.log(isFileExist('abcdefghijklmnopqrstuvwxyz123456789-_ABCDEFGHIJKLMNOPQ')); Logger.log(isFileExist('1vSZehxRr68K7oTBbLnK8WAema1ebG1d6xahSWYsn2ct2L2hN8rpoW')); } function isFileExist(id) { return getFile(id).err ? false : true; } function getFile(id) { try { return DriveApp.getFileById(id); } catch (err) { return { err: err }; } }