I have this situation. I had done a script few month ago that is still running on a google sites. The doGet Function is :
function doGet(e) {
var myapp = UiApp.createApplication();
var mygrid = myapp.createGrid(5, 2);
var listboxAssociazione=myapp.createListBox().setId("listboxAssociazione").setName("listboxAssociazione");
var labelAssociazione=myapp.createLabel("Associazione").setId("Associazione");
var listboxMeseFatturato=myapp.createListBox().setId("listboxMeseFatturato").setName("listboxMeseFatturato");
var labelMeseFatturato=myapp.createLabel("Mese da fatturare").setId("Mese da fatturare");
var listboxAnnoFatturato=myapp.createListBox().setId("listboxAnnoFatturato").setName("listboxAnnoFatturato");
var labelAnnoFatturato=myapp.createLabel("Anno").setId("Anno");
var buttonCalcola=myapp.createButton().setText("Calcola").setId("CalcolaFattura");
var labelLavoroInCorso=myapp.createLabel("").setId("labelLavoroInCorso").setStyleAttribute('color', 'blue');
mygrid.setWidget(0, 0,labelAssociazione);
mygrid.setWidget(0, 1, listboxAssociazione);
mygrid.setWidget(1, 0, labelMeseFatturato);
mygrid.setWidget(1, 1, listboxMeseFatturato);
mygrid.setWidget(2, 0, labelAnnoFatturato);
mygrid.setWidget(2, 1, listboxAnnoFatturato);
mygrid.setWidget(3, 1, buttonCalcola);
mygrid.setWidget(4, 1, labelLavoroInCorso);
var p=DocsList.getFolders();
var totcartelle = p.length;
var trovato= false;
var cartellaAssociazioni;
for(var j=0;j<totcartelle && trovato==false;j++){
var prova=p[j].getId();
if(p[j].getId()=="0B-H4Ioaio5w5YTg3MGFkOWQtMzYzNy00ZTFhLWEzY2YtZTVlNzIwYWJhMmJm"){
trovato=true;
cartellaAssociazioni=p[j];
}
}
var cartelle =cartellaAssociazioni.getFolders();
var lunghezza = cartelle.length;
for(var i = 0; i < lunghezza; i++) //these arrays are zero based it looks like
{ var prova=cartelle[i].getName();
listboxAssociazione.addItem(prova);
}
//Aggiunta dei mesi alla listbox
listboxMeseFatturato.addItem("Gennaio");
listboxMeseFatturato.addItem("Febbraio");
listboxMeseFatturato.addItem("Marzo");
listboxMeseFatturato.addItem("Aprile");
listboxMeseFatturato.addItem("Maggio");
listboxMeseFatturato.addItem("Giugno");
listboxMeseFatturato.addItem("Luglio");
listboxMeseFatturato.addItem("Agosto");
listboxMeseFatturato.addItem("Settembre");
listboxMeseFatturato.addItem("Ottobre");
listboxMeseFatturato.addItem("Novembre");
listboxMeseFatturato.addItem("Dicembre");
//Aggiunta dell'anno di fatturazione
var d= new Date();
var annoAttuale=parseInt(d.getFullYear());
listboxAnnoFatturato.addItem(""+annoAttuale);
listboxAnnoFatturato.addItem(""+(annoAttuale-1));
var formpanel=myapp.createFormPanel().setId("form");
var serverClickHandler = myapp.createServerClickHandler('GeneraFattura');
serverClickHandler.addCallbackElement(formpanel);
buttonCalcola.addClickHandler(serverClickHandler);
var serverClickHandlerStatus = myapp.createServerClickHandler('ChangeStatus');
serverClickHandlerStatus.addCallbackElement(formpanel);
buttonCalcola.addClickHandler(serverClickHandlerStatus);
formpanel.add(mygrid);
myapp.add(formpanel);
return myapp;
}
//Function to disable the button to avoid double click
function ChangeStatus(e){
var app = UiApp.getActiveApplication();
app.getElementById("labelLavoroInCorso").setText("Attendere! Calcolo della richiesta di pagamento in corso...");
app.getElementById("CalcolaFattura").setEnabled(false);
return app;
}
Now my problem is that when i click the button "Calcola" in the site, it seems that the function "GeneraFattura" runs a number of random times instead of 1.
If i run the same function from the script editor in Google site with the same 3 parameter given by me
var valoreAssociazione = "Volley";
var valoreMese="May";
var valoreAnno = "2012";
instead from the form above, it works correctly.
When i say it works correctly i mean that in the function "GeneraFattura" there is only one line where i copy a spreadsheet. If i run the script from the script editor the output is one copy of the spreadsheet, if i run the script from the sites i get 5 6 copy of the spreadsheet.
Where do you think is the problem??Why a different behaviour between google sites script editor execution and the script execution embedded in the google site??
Thank you in advance