2

Background: I have been learning Google Apps script, and now have a working standalone Google Apps Script project, just for personal use, in which I have created an Installable Trigger that is configured with Event Source: "From Spreadsheet", creating it programmatically (I was unable to find a way to create this trigger through the web interface (Edit menu --> Current project's triggers) since the event source drop-down only shows "timed" and "From Calendar" as selections).

A few weeks back I reached the point where I split the spreadsheet & script project into "production" and "development versions, and I have so far just been copying/pasting the development code into the production project when I want to release new versions.

It seems, a much better way to do this would be to take advantage of the Deployments logic, so that I can support both environments from a single code base, with development using the HEAD deployment, and then create a separate Deployment for production.

The problem: The problem I'm running into here is, after creating a new deployment, I see no way to associate my newly created "production" deployment to be able to take events from any spreadsheet. If I try to create the trigger manually through Edit --> Current project's triggers --> create trigger, the options available permit me to select which deployment I want to use for it, but don't allow me to select "From Spreadsheet" as an event source; and if I create the trigger programmatically, I can associate the event source correctly, but it creates the trigger associated with the HEAD deployment, and without any way I can see to specify a different deployment.

ScriptApp.newTrigger('ss_onEdit')
  .forSpreadsheet(idSs)
  .onEdit()
  .create();

I had thought perhaps I could change which deployment the trigger goes against, post-creation, but the drop-down to select a different deployment is greyed-out.

Is it possible to do what I'm trying to do? Am I misunderstanding something about how this is supposed to work? At this point I don't really see the point of a versioned deployment if there is no way to associate it with a trigger.

flashfasbo
  • 21
  • 3
  • Is this thread useful for your situation? https://stackoverflow.com/q/54210044/7108653 – Tanaike Sep 28 '19 at 23:39
  • Hard for me to answer that at this time, as I have no experience yet creating and deploying libraries. It just seemed that all the puzzle pieces were (nearly) there already to make it work without need for that. I will explore the library idea to see how workable it is for my use case, and report back. thank-you. – flashfasbo Sep 29 '19 at 00:38
  • Thank you for replying. If that didn't resolve your issue, I apologize. – Tanaike Sep 29 '19 at 02:36

1 Answers1

1
  • The script needs to be bound to the spreadsheet(accessible from Tools> Script editor of the spreadsheet).
  • You need to publish and deploy a dummy web-app/api. In the editor,

    • Publish> Deploy as Web-app> Select a version and deploy

You can now select any of the deployed versions in the web interface(Edit> Current project triggers) to add trigger and select a version.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • I'd have to look into that, but currently my project does not use doGet() or doPost() functions, which appears to be a requirement for [web apps](https://developers.google.com/apps-script/guides/web). Apart from that, I assume this idea provides a similar workaround to the [Library](https://developers.google.com/apps-script/guides/libraries) approach. Would you agree? – flashfasbo Sep 30 '19 at 19:25
  • @flash I can't comment on the library approach. However, try publishing without `doGet()` or anything else. We just need a dummy deployment/entry point – TheMaster Sep 30 '19 at 19:34