Reputation: 73
I have a Google App script that is being executed by clicking on an floating image on a sheet.
How can I prevent people from running the script AGAIN before it is finished with the first execution?
It seems that you can execute the script multiple times by clicking the image and that the subsequent executions conflict with the previous ones and cause erroneous results.
I was going to temporarily disassociate the script with the floating image while it is running an then restore it before exiting the script but I can't seem to find a way to manipulate the floating image's properties.
Upvotes: 4
Views: 4032
Reputation: 3355
For client side handling, you can assign a value to a variable to identify the status of function.
index.html
<!DOCTYPE html>
<html>
<body>
<img src="http://cdn.soulsplay.com/assets//listing/css/comments/submit-button-2.png" onclick="invokeSubmit();">
</body>
<script>
var image_clicked = 0;
function invokeSubmit(){
image_clicked ++;
if(image_clicked == 1){
alert("Processing");
google.script.run.withSuccessHandler(function(){
image_clicked = 0;
alert("done");
}).sleep_func();
}
}
</script>
</html>
code.gs
function doGet() {
var output = HtmlService.createTemplateFromFile('index').evaluate();
output.setSandboxMode(HtmlService.SandboxMode.IFRAME);
output.setTitle('App Script');
return output;
}
function sleep_func(){
Utilities.sleep(15000);
return;
}
You can also prevent the script from concurrent access by using Lock Service.
function test_func(){
var lock = LockService.getScriptLock();
lock.waitLock(15000);
//Some operations
lock.releaseLock();
}
Upvotes: 7