1
votes

I have been using ScriptApp.getService().getUrl() server side to return the current dev or prod (exec) url to the client side. I do this so that I can provide a "permalink" or copy URL function so that users can link to a specific record in the app. Something like:

https://script.google.com/macros/s/{ID}/exec?recordId=999

Recently, when Google rolled out the new IDE, I started having a problem where ScriptApp.getService().getUrl() returns only the Legacy URL.

I was able to recreate this with a new project, so maybe this is a new IDE bug?

Steps to Recreate

  1. Create a new App Script Project.
  2. Make sure you select "Use Legacy Editor"
  3. Create an app that displays the URL

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  </head>
  <body>
    <h2>Hello World 2</h2>
    <div id='test'>xx</div>
      <script>
      $(document).ready(function() {
          google.script.run.withSuccessHandler(success).getUrl();
      });

      function success(url) {
          $("#test").html(url);
      }
  </script>
  </body>
</html>

Code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index');
}

function getUrl(){
  Logger.log(ScriptApp.getService().getUrl());
  return ScriptApp.getService().getUrl();
}
  1. Menu Publish -> Deploy as Web App (old IDE).
  2. Open the new deployed app, and confirm that the URL on screen is the same as the URL you're hitting.
  3. Menu Publish -> Deploy as Web App, click "Latest Code" link to get to dev.
  4. Verify it shows the correct dev URL.
  5. Click "Use new Editor" button to switch to new IDE.
  6. Click Deploy -> New Deployment.
  7. Enter a description and click "Deploy"
  8. Now open the new URL that is published.
  9. Note how the URL in the address bar and the URL on the page from the getURL call are different: on Page is the same as the old IDE URL.

So the question is: How do I get Google to completely archive the old URL?

2
You might have to create a new issue in the issuetracker. See tag info page for more details.TheMaster
This issue has already been filed: issuetracker.google.com/170799249.ziganotschka
Thank you. Agreed, it looks like the same issue. I'll monitor for resolution.John Piechowski

2 Answers

1
votes

(my response from issue tracker, here for reference https://issuetracker.google.com/issues/170799249#comment26)

In legacy editor user had to save new project version and then publish it (or do it at once) There were two links: dev (head) and published version with static link (web app meta-version)

In a new editor, every time project is deployed it gets a new ID and new link but web app meta-version is not updated. There is no way to control this published with the static link version (web app meta-version). So bookmarks and reverences point to the old version or are broken if this version was archived. This is BAD!

ScriptApp.getService().getUrl() seems to always return the same static link to web app meta-version. This what is confusing OP IMHO.

Workaround that worked for me: switch to legacy editor, publish (deploy as web app) the latest (or required) version. It will became web app meta-version reachable by the same old link. I assume the same returned by ScriptApp.getService().getUrl(). Not sure about dev link.

0
votes

Few days ago Google make it possible to create and assign a version to a deployment.

Resources