Possible configuration issue with google.script.run executing server side function from HTML modal

187 views
Skip to first unread message

Amelia Milne

unread,
Mar 19, 2024, 2:46:42 AM3/19/24
to Google Apps Script Community
Hey there!

I'm having this issue in one of my AppsScript projects where the function I'm calling from my HTML modal using google.script.run isn't being run. I created a new AppsScript project with the exact same code, file order and appscript.json file, and it works! Unfortunately I need it to work in my original AppsScript project as well, since the spreadsheet is attached to is shared with others. (I also posted my question on Stack Exchange: https://stackoverflow.com/questions/78173700/function-isnt-executing-using-google-script-run?noredirect=1#comment137824961_78173700)

Here is my HTML code:

<html>
<head>
<title>HTML</title>

crossorigin="anonymous" referrerpolicy="no-referrer" />
referrerpolicy="no-referrer"></script>
<script>
$(function () {
$("#datepicker").datepicker({
beforeShowDay: function (d) {
var day = d.getDay();
return [day != 0 && day != 2 && day != 3 && day != 4 && day != 5 && day != 6];
},
});
});
</script>
</head>
<body align="center">
<form id="Form" onsubmit="runThis()">
<input type="text" id="datepicker" value="YYYY-MM-DD"/>
<input type="submit" value="Submit">
</form>
<script>
function runThis() {
alert("Hi!");
google.script.run.withFailureHandler(e => alert(e)).doSomething();
}
</script>
</body>

</html>

Here is my apps script code:

function calendar() {
var html = HtmlService.createHtmlOutputFromFile("CalendarInput");
SpreadsheetApp.getUi().showModalDialog(html, "Choose the Monday start date from the calendar:");
}

function doSomething() {
SpreadsheetApp.getActive().toast("hello");
console.log("doing something");
return true;
}

In the project where it is not working, when I hit "submit" in the HTML modal, the alert "Hi" shows up so I know it is running the function runThis() in the HTML code. But it isn't running doSomething(). I checked my execution history and doSomething() isn't there. When I run doSomething() in the console, I successfully get the toast and log. When I wrap it in a failure handler, it fails every time with NetworkError: Connection failure due to HTTP 500.

But like I said, when I copy and pasted the code into another project, it works just fine. Does anyone know if I am missing something with configuration or might be causing this error?

Thank you so much!

Amelia Milne

unread,
Mar 20, 2024, 2:59:04 AM3/20/24
to google-apps-sc...@googlegroups.com
Solved! I was using the Head (development) version of my imported libraries. Deleting them, deploying them and re-adding them as a versioned deployment fixed my issue. I solved this by accident because I was having an issue creating new triggers which gave the error: "Script authorization failed. Please check your pop-up blocker settings and try again", which versioned libraries also fixed. I hadn't had any problems using the HEAD of libraries before but I guess it can cause some random issues. However, I don't understand why this caused these issues. If anyone has an explanation that would be much appreciated. Thank you!

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/73e6d882-bd6d-4f65-ab68-e9f2db3b35c2n%40googlegroups.com.

Amelia Milne

unread,
Mar 20, 2024, 2:59:05 AM3/20/24
to Google Apps Script Community
Solved! I was using the Head (development) version of my imported libraries. Deleting them, deploying them and re-adding them as a versioned deployment fixed my issue. I solved this on accident because I was having an issue creating new triggers which gave the error: "Script authorization failed. Please check your pop-up blocker settings and try again", which versioned libraries also fixed. I hadn't had any problems using the HEAD of libraries before but I guess it can cause some random issues. However, I don't understand why this caused these issues. If anyone has an explanation that would be much appreciated. Thank you!
Reply all
Reply to author
Forward
0 new messages