Renaud Tarnec
Renaud Tarnec

Reputation: 83058

Batch update of the Apps Script of a set of Google Sheets

I have a large set of Google Sheets which have exactly the same Apps Scripts code (several gs files in each Sheet).

Is it possible to update the code of these Sheets with a batch update, instead of opening each Sheet and pasting the new code in each gs file?

Upvotes: 0

Views: 733

Answers (2)

stowssnov
stowssnov

Reputation: 21

User scripts are easily updated using the ScriptSync library.

You need to execute the code in a custom script.

  // Initialize the template script updater
  const updater = ScriptSync.assignTemplate(template_script_id);

  // get an array of files to copy from the template
  const filesToCopy = ScriptSync.getScriptFiles(template_script_id);

  filesToCopy.forEach(function(item) {
    if (item.file !== 'appsscript') {
      // add the file to the updater
      updater.AddNewFile(item.file);
    }
  });

  // apply the changes
  updater.commit();

Upvotes: 1

Marios
Marios

Reputation: 27348

No unfortunately, you can't update scripts by using a script.

You can write your master code somewhere and then duplicate the spreadsheet file so all of them will have the same code.

A better approach would be to create your own Library which will contain the full code and all the other spreadsheets will import this library. So you only need to update the code in one place.

Upvotes: 1

Related Questions