2
votes

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.

1
Is this thread useful for your situation? stackoverflow.com/q/54210044/7108653Tanaike
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
Thank you for replying. If that didn't resolve your issue, I apologize.Tanaike

1 Answers

1
votes
  • 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.