I have search for hours and cant find a solution to this. I have some appscript code that creates a menu and open a modal in google docs:
function showDialog() {
let ui = DocumentApp.getUi();
let html = HtmlService.createHtmlOutputFromFile("dialog");
ui.showModalDialog(html, "dtest");
}
function processForm() {
console.log("test123123123");
}
This works, the modal opens.
In the modal i want to submit a form. For now im just calling a test function when submitting that console.logs to the cloud logger.
<script>
// Prevent form from submitting
function preventFormSubmit() {
var forms = document.querySelectorAll("form");
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener("submit", function (event) {
event.preventDefault();
});
}
}
window.addEventListener("load", preventFormSubmit);
google.script.run.processForm();
</script>
The problem here is that the function processForm() is not triggered.
BUT when i use a doGet() and deploy it as a webapp it works.
How can i get it to work in google docs also? I have tried following the documentation..but i cant get it to work.
Thanks in advance for any help with this.
So i found the problem. I was singed into google with account A, the correct one. And prompts with input and everything worked. In chrome i was signed in with account B. It seems that when you use htmlservice it uses a sandbox, and it uses the user you are logged into chrome with, not the one you are logged into workspace with. So access denined. Use same users both places to solve this problem.