I understand that your goal is to take an existing Form/Sheet pair, delete the Sheet, create a new Sheet and join it to the original Form. If my understanding is correct, then you only need some small tweaks in your code to achieve your objective.
First thing is to change the old response Sheet for the new one. With Form.getDestinationId()
you can get the ID of the old response Sheet (it will be useful later for cleaning up). Then you could use Form.setDestination()
to make the change happen. If you didn't create the new response Sheet yet, you can use SpreadsheetApp.create()
to do so.
If that ended fine, then you can send the old Sheet to the trash bin using DriveApp.getFileById().isTrashed()
and finish this approach. Please, let me know if you have any questions about this process.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…