0

I have a spreadsheet that has a function to call an HTML dialog to choose some dates:

htmlDate =  HtmlService.createHtmlOutputFromFile('datePicker')
    .setHeight(120)
    .setWidth(550);

SpreadsheetApp.getUi().showModalDialog(htmlDate, 'Select the dates for presentation:');

This is the part of the HTML code that defines the actions of buttons in datePicker.html:

<input type="button" onClick="submitForm()" value="OK" />
<input type="button" onClick=google.script.host.close() value="Cancel" />

And this is the part of HTML code that calls my function 'newPresentation':

<script type="text/javascript">    
    function submitForm() {

      google.script.run.newPresentation(document.forms[0]);
      Utilities.sleep(1000);
      google.script.host.close();

    }        
</script>

The problem is that: When I run the script, it works perfectly. First, it calls my function 'newPresentation', and then it closes itself, running the rest of the script. In function 'newPresentation' there are other HTML dialogs that are called up.

But, when another user runs the script, this HTML dialog doesn't close itself. Even though it doesn't close itself, the rest of the script is executed normally. I have already shared the spreadsheet with another user, with edit privileges. Both me and the other user are logged in a Google Account.

Some idea how to fix that problem?

PS.: Sorry for some grammatical errors, but I'm not fluent in english.

matthias_h
  • 11,356
  • 9
  • 22
  • 40

2 Answers2

1

Try this:

google.script.run
.withSuccessHandler(function(){google.script.host.close();})
.newPresentation(document.forms[0]);

and put a return at the end of newPresentation();

Another possibility is to try using the dummy dialog described here: https://stackoverflow.com/a/55731456/7215091

Cooper
  • 59,616
  • 6
  • 23
  • 54
  • I have tried the script above, but no success. I think that the problem is not the logic, because it works for my user. The problem just occurs when other users try to run the script. What kind of return i should to put at the end of newPresentation? Could you explain? – Luiz Mesquita Apr 08 '20 at 21:08
  • I usually just send it something even if I'm not going to use it. So that it will return to the SuccessHandler and run google.script.host.close(). Oh any by the way google.script.host.run does not work in a webapp. – Cooper Apr 08 '20 at 21:14
  • 1
    Oh I just noticed that you are using Utilities.sleep() clientside and that's not allowed. Utilities is server side only. All of the methods documented in Google Apps script are server side. Many pure javascript functions work in both environments. – Cooper Apr 08 '20 at 21:17
0

I'm not certain of the reason that issue occurs. In all tests that i haved make, i used the same computer, with two windows of Google Chrome (one for each user logged in). I can't resolv the problem.

After that, i have tested in a new computer, with one single user logged in, and the script works perfectly.

Aparently, may be some problem related with some cache in browser, or something. I really don't know.