0

I have created a HTML UI for google sheets that allows a user to select 2 variables from dropdowns that then are passed to the Code.gs to execute. What I am observing is that occasionally when a the 'Create' button is pressed the code does not execute!

Is there an issue with using onmouseup in this case or could my problem be something else. It appears like the Google servers are slow to respond and that the variables are not passed when the dialog closes. I have removed the google.script.host.close() code so that the dialog does not close when 'Create' is pressed and it seems to work?? Is there a way of ensuring that the server side code executes?

<hr>

<button onmouseup="closeDia()">Close</button>
<button onmouseup="createSheet()">Create</button>

</div>

<script>
    window.closeDia = function() {
    google.script.host.close();
  };

   window.createSheet = function() {
   var monthVar = document.getElementById("monthSelect").value;
   var yearVar = document.getElementById("yearSelect").value;
    google.script.run.duplicateMaster(monthVar,yearVar);
    google.script.host.close();
  };

</script>
  • Please write out the solution as a separate answer and accept your answer, this way the question is marked answered. – Jack Brown Feb 16 '17 at 20:11
  • That wasnt a solution, it was just additional information, my problem still persists. – JJ_Australia Feb 16 '17 at 22:24
  • Have you looked into google.script.run.withSuccessHandler? https://developers.google.com/apps-script/guides/html/reference/run#withSuccessHandler(Function) this will ensure server side functions runs first before you close the dialog is called. – Jack Brown Feb 16 '17 at 22:41
  • @JagannathanAlagurajan I have but it returns a value only on success of the script, problem I am getting is sometimes the script just wont run and sometimes it does, it is somewhat inconsistent. – JJ_Australia Feb 19 '17 at 13:26

1 Answers1

1

This is very likely related to using onMouseUp instead of click, it can be finnicky if you click down on the button but inadvertently move the pointer off the button before releasing. It is easier to do this than it sounds, and might not be visually obvious.

You can use onclick instead:

<button onclick="closeDia()">Close</button>
<button onclick="createSheet()">Create</button>
Cameron Roberts
  • 7,127
  • 1
  • 20
  • 32
  • Thanks but even changing to onclick problem still persists. The script is meant to copy a sheet from another spreadsheet to the current spreadsheet, but it doesn't always get executed. – JJ_Australia Feb 19 '17 at 13:30