2

I'm using HtmlService to submit a simple form to my script for processing. I'm using jQuery to do things like input validation. I created a form and a formSubmit() function for my submit button:

<input type='button' onclick='formSubmit()' value='Submit' />

And for my JS:

function formSubmit(){
   //verify inputs
   //if inputs are good
   google.script.run.withSuccessHandler(success).withFailureHandler(fail).submit(document.forms[0]);
}

I have isolated the problem to withSuccessHandler() and it only started happening a few days ago. When this is present, it calls my script over and over again. Sometimes in 1 minute intervals, sometimes every 2-3 minutes. The only way to stop the execution is to close the browser window. Here is the success() function:

function success(e){
  $('#dialog-body').html(e.body);
  $('#loading').fadeOut(100, function (){
    $('#btnSubmit').fadeIn(100);
    $('#dialog').dialog( "open");
    $('#txtEmail').val("");
    document.getElementById('txtEmail').disabled=true;
    document.getElementById('chkEmail').checked=false;
    document.getElementById('chkShare').checked=false;
  });
}

*Update: After testing this for a while longer, I can't even be sure it is just .withSuccessHandler() - it seems to be anytime I use the google.script.run service at all. The problem is intermittent. I have tried other methods of running the script and they all work fine.

Greg
  • 697
  • 1
  • 8
  • 22

1 Answers1

1

I am unable to see this issue. I've written a small app that works perfectly. Perhaps somewhere else in your client side code there is a setTimeout or some other loop that is kicking in?

Code.gs ("server side")

function submit(e) {return 'Recieved ' + e.simpleTextField;}

function doGet(){return HtmlService.createHtmlOutputFromFile('ui');}

ui.html ("client side")

<html>
<script>
function formSubmit(){
   google.script.run.withSuccessHandler(success).withFailureHandler(fail).submit(document.forms[0]);
}
function success(e){alert(e);}
function fail(e){console.log(e);}
</script>
<body><form>
<input type='text' name='simpleTextField' />
<input type='button' onclick='formSubmit()' value='Submit' />
</form></body>
</html>

This works fine and I only see one popup ever displayed. If success gets called multiple times, then I would see multiple popups which I dont see.

Here is the app in action and here is the source code (view-only).

Arun Nagarajan
  • 5,547
  • 1
  • 22
  • 19
  • I get positive results when running simpler script processes. The script takes a GmailLabel, and processes it doing various things. If the label is relatively small, it works as desired. If it has 300+ messages - then I see the errors (intermittently, more often than not). You can view the source [here](https://script.google.com/d/17wP1wqdcShrn5_agDT3NInziKB5_8Y0oNafcUanK1R5RLw2kdVy-T2du/edit?usp=sharing) and the script in action [here](https://script.google.com/macros/s/AKfycbzThjETaVtipox9aDTqCiaRCPMHCtyp6yHzhzYyStq8WlCGH8M/exec). – Greg May 14 '13 at 21:55
  • Also, I built a interface using UiApp and it behaves the same way. The script worked as desired up until a couple of weeks ago. Previous working versions also behave like this now when I restore them. I can successfully run the script from the editor by creating a function that calls the clickHandler function and passes it the params manually. – Greg May 14 '13 at 22:02
  • Greg - roughly, how long before your operation re-tries? Can you look at the Chrome Dev Tools to see if a new HTTP call is being made? See info here - https://developers.google.com/chrome-developer-tools/docs/network – Arun Nagarajan May 22 '13 at 22:41
  • After trying a few scenarios, nothing in the Network profiler or the console indicates that it is making a new call. Based on the output the script makes in my Drive, it seems to be about every 1.5 - 2 minutes. – Greg May 23 '13 at 05:21
  • Greg, if there is a new called made in HtmlService, there HAS to be something in the Network profiler as its made over HTTP. I was finally able to see something when I added a 3-4 minute delay and I re-ran once. This is not the same as the UiApp retry issue as they are very different. – Arun Nagarajan May 23 '13 at 13:12
  • I apologize, for some reason I didn't see the request when I tested before, but after some more testing this morning I can see that the flow is 1)Click the submission button 2) json POST sent to the server only once, and the only time a response comes is if the try/catch I have the script wrapped in returns an exception to the failure handler. 9/10 times the exception is a ratemax because there are concurrent runs stumbling over each other. There are no evident new requests making the concurrent runs happen, at least not in the profiler. – Greg May 23 '13 at 14:46
  • Ok. So you see 1 HTTP request (correctly) corresponding to the user action that returns back 9/10 times to your `withFailureHandler`. Correct? Now digging deeper - How do you know your server code is running multiple times? Is it because you get rate limiting errors or do you have other details to support that assertion? – Arun Nagarajan May 23 '13 at 16:02
  • Yes, the script is supposed to create 1 parent folder that it creates all the documents in. This folder creation is one of the first things the initialization/handler function does, and should only happen once. After the button is clicked, I see the pending POST, and it still shows pending while the folder is re-created and re-populated in the 2 minute interval described above. If an an exception is thrown, then the pending request returns the response. If no exception is thrown (i.e the other 1/10) then the request continues to show as pending while multiple folders are created. – Greg May 23 '13 at 16:12
  • Acknowledged this as an issue on the issue tracker - https://code.google.com/p/google-apps-script-issues/issues/detail?id=2734. Seems related to complex regular expressions but we are still investigating. Please accept this question so the conversation can be continued on the issue tracker. – Arun Nagarajan May 30 '13 at 13:52