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
- Create a new App Script Project.
- Make sure you select "Use Legacy Editor"
- 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();
}
- Menu Publish -> Deploy as Web App (old IDE).
- Open the new deployed app, and confirm that the URL on screen is the same as the URL you're hitting.
- Menu Publish -> Deploy as Web App, click "Latest Code" link to get to dev.
- Verify it shows the correct dev URL.
- Click "Use new Editor" button to switch to new IDE.
- Click Deploy -> New Deployment.
- Enter a description and click "Deploy"
- Now open the new URL that is published.
- 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?