/**
* @see https://developers.google.com/apps-script/reference/script/script-app#getService()
* ATTENTION: Since V8 (approx. 2020)
* Contrary to the documentation, ScriptApp.getService().getUrl() fails to get the url of the deployed web app.
* Google is aware of the issue but refuses to fix it
* @see https://tanaikech.github.io/2022/06/11/report-recent-value-of-scriptapp.getservice.geturl-in-google-apps-script/
* @see https://issuetracker.google.com/issues/170799249
* @see https://issuetracker.google.com/issues/184467246
* @see https://issuetracker.google.com/issues/193095356
* @see https://issuetracker.google.com/issues/235862472
*/
function logging(){
const url = ScriptApp.getService().getUrl(); // Fails to get the correct url of the deployed web app.
Logger.log(url)
}
/**
* WORKAROUND: IF feasible, manually configure the url of the web app into the script after it's been deployed.
*/
function onOpen(){
const ui = SpreadsheetApp.getUi();
ui.createMenu("Admin Menu")
.addItem("Open the Web App", "openWebApp")
.addToUi();
}
function openWebApp(){
const url = 'https://script.google.com/macros/s/AkFYCbmN7-ZPc2xjLkGxu-7eUi18zPnp_-HxfOrmJSirTbA5KFfZ9r186TSiIcNpw-xoU9pl/exec'; // Replace with your actual web app URL
const html = "<script>window.open('"+ url +"');google.script.host.close();</script>";
const userInterface = HtmlService.createTemplate(html).evaluate().setHeight(200).setWidth(400);
SpreadsheetApp.getUi().showModalDialog(userInterface, "Opening...");
}