5
votes

According to the documentation, this method should return the URL of the web app:

"Returns the URL of the web app, if it has been deployed; otherwise returns null. If you are running the development mode web app, this returns the development mode url."

We have a Google Calendar add-on in which we have custom settings page (html) delivered to the clients using HtmlService and I have no idea how ScriptApp.getService().getUrl() works with versioned deployments.

Here's an interesting scenario:

On a fresh Google Script project, we deployed from manifest file (NOT webapp, although we have the "webapp" part on the manifest)

  1. First versioned deployment from manifest:

    ScriptApp.getService().getUrl() correctly returns https://script.google.com/a/gong.io/macros/s/AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr/exec

    Versioned Deployment ID: AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr

  2. Made some changes, created a new versioned deployment

    ScriptApp.getService().getUrl() correctly returns https://script.google.com/a/gong.io/macros/s/AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq/exec

    Versioned Deployment ID: AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq

  3. We've deployed the script through Publish->Deploy as web app... Probably done this mistakenly on our production script

    Web app URL is https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec

  4. Another round of code changes to the script. This time we deployed from manifest:

    ScriptApp.getService().getUrl() incorrectly returns https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec

    Versioned Deployment ID: AKfycbx29Pcs8_cpEkodrfWGklz8t_OAs87OBSEtxLMkStrya64wUV4M2ePW_tNTTWlq0_T1

Notice that this time - we got the webapp deployment ID - not the versioned deployment id.

From here on, no matter what I've tried - I will ALWAYS get https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec no matter what we do.

  1. Deleted all versioned deployments and created a new one
  2. Disabled web app

enter image description here

As of now, everything I do ends up in ScriptApp.getService().getUrl() returning this URL.

How can I reset it and get getUrl() to return the versioned deployment ID rather than a non-existing webapp deployment ID?

edit: typos

2
I cannot reproduce this same behaviour. getUrl() returns the /dev URL if I have deployed a new version from manifest but haven't deployed the webapp via Publish > Deploy as web app.... Could you please share the code related to the manifest file, in case I'm missing something? Also, when publishing as Deploy as web app..., the following message appears: A new link will be given when you click Update. The current link will continue to work. So it seems that when the web app is deployed this way, a new URL is generated that overrides the one created from manifest, but both work.Iamblichus
Considering all this, what are you using the URL for? If I may ask, why is the one created via Deploy as web app... not appropriate, and you want the ones corresponding to the versions deployed from manifest?Iamblichus
We are hosting a couple of HTMLs for the add-on settings and wouldn't want to bother with manually updating URLs in our calendar add-on.yarinbenado
For me getUrl() returned the right version. This was tested on the actual settings URL on Google calendar (as opposed to executing the function from the editor - where indeed it's the /dev URL). So what exactly is ScriptApp.getService().getUrl() is returning? If I have multiple versions deployed with Publish > Deploy as web app...?yarinbenado
Better to create a issue in the issuetracker. See tag info page for more details.TheMaster

2 Answers

4
votes

This might to be a bug.

This issue was reported in Issue Tracker (I'm guessing you did it), and now it got forwarded internally. Posting this here to give it more visibility:

To anyone affected by this, please click the top-left star.

0
votes

From https://issuetracker.google.com/issues/170799249#comment30 (my own comment)

Few days ago Google make it possible to create and assign a version for an existing deployment. See Release Notes 2021-03-15