Search code examples
google-sheetsgoogle-apps-scriptgoogle-cloud-platformgoogle-sheets-api

Duplicate sheet along with its scripts


I have a template google sheet that I use as a registration form. It has a attached google apps script that, when the submit button is clicked, scrapes the data from the sheet and sends it to my BE. Each user should have his own registration form (google sheet) that is cloned from the template. This cloning is done by another google apps script that uses copyTo() to create this new copy. However, the script does not seem to be copied - when the user in his sheet clicks on the submit button, it just shows error that the target apps script function was not found.

What am I missing? Why is the script not copied? I even have it in a separate GCP project (the same project that my BE - cloud function and buckets - reside).


Solution

  • Bound script projects get copied along the spreadsheet when you make a copy of the whole spreadsheet file.

    The copyTo() method is not available for Spreadsheet objects, which indicates that you are not copying the whole spreadsheet but just a single Sheet object, i.e., a tab in the spreadsheet. That does not automatically copy the bound script project.

    You can make a copy of the whole spreadsheet with File.makeCopy().

    Note that running a script through a button requires that the user first authorizes the script, which may cause confusion unless you explain the matter to users in advance.

    template google sheet that I use as a registration form

    Have you considered creating a Google Form instead of sharing a spreadsheet for data input? Form responses automatically appear in a separate tab in the spreadsheet in a row-oriented fashion and are thus easy to process with spreadsheet functions such as query() and filter(). Google Forms require no authorization and cause a lot less hassle.