I try to change a sheets with a script but it doesn't work as expected. I can load the right panel, but nothing happens when I try to record the change. It seems "masterFunctionPS" isn't called. The function periodSelection post the panel, the listbox and the button. But nothing append, when I clic on the Button. Nothing change in the sheets.
function periodSelection() {
var activeSS = SpreadsheetApp.getActiveSpreadsheet();
var sheetPS = activeSS.getSheetByName("Periods");
var uiPS = UiApp.createApplication().setWidth(300);
var panelPS = uiPS.createVerticalPanel();
var periodPS = uiPS.createListBox();
for (var i = 2; i < 13; i++) {
var range = "A" + i;
periodPS.addItem(sheetPS.getRange(range).getValue());
}
var endDatePS = uiPS.createDatePicker();
var recordPS = uiPS.createButton("Enregistrer");
var masterPS = uiPS.createServerHandler('masterFunctionPS');
masterPS.addCallbackElement(periodPS)
.addCallbackElement(endDatePS)
recordPS.addClickHandler(masterPS);
panelPS.add(periodPS);
panelPS.add(endDatePS);
panelPS.add(recordPS);
uiPS.add(panelPS);
SpreadsheetApp.getUi().showSidebar(uiPS);
return uiPS;
}
function masterFunctionPS(element) {
var parameterPS = element.parameter;
var appE = UiApp.getActiveApplication();
var periodE = parameterPS.periodPS;
var endDateE = parameterPS.endDatePS;
var activeE = parameterPS.activeSS;
var sheetE = parameterPS.sheetPS;
switch (periodE) {
case "P1":
sheetE.getRange("C2").setValue(endDateE);
break;
case "P2":
sheetE.getRange("C3").setValue(endDateE);
break;
case "P3":
sheetE.getRange("C4").setValue(endDateE);
break;
case "P4":
sheetE.getRange("C5").setValue(endDateE);
break;
case "P5":
sheetE.getRange("C6").setValue(endDateE);
break;
case "P6":
sheetE.getRange("C7").setValue(endDateE);
break;
case "P7":
sheetE.getRange("C8").setValue(endDateE);
break;
case "P8":
sheetE.getRange("C9").setValue(endDateE);
break;
case "P9":
sheetE.getRange("C10").setValue(endDateE);
break;
case "10":
sheetE.getRange("C11").setValue(endDateE);
break;
case "P11":
sheetE.getRange("C12").setValue(endDateE);
break;
}
return (appE);
}