google-apps-scriptgoogle-apps-script-editorgoogle-apps-script-apigoogle-apps-script-addon

How to copy a Google sheet and keep it's project triggers and scripts?


I currently have a Google Sheet that I'm using as a master template. That is, I'm making a copy of this template for every request. I want to add a Google App Script (which onEdit POSTs to my server when the sheeting is completed) to my master template that will be duplicated and run for every copy of this template.

I've tried doing this from an admin account, however, the scripts don't seem to 'stick' with any of the templates. Is this possible?


Solution

  • Installable triggers can be attached to any spreadsheet (respecting sharing permissions) from any project. You can add a new trigger to your master sheets project for each copy that is made. In the second example here they suggest using SpreadsheetApp.openById() you could also use SpreadsheetApp.openByURL() or the Spreadsheet returned by Spreadsheet#copy() depending on how you are duplicating your spreadsheet.