0
votes

Trying to do something which seems like it should be simple:

I have a small gui application in Google scripts. I would like to make a datePicker object appear, with the value (starting date) of a cell in the spreadsheet which the app works. I have looked through many of similar questions on stackOverFlow, but still can not find an answer that works.

For example, cell (2,5) in my sheet has a date in it, formated by Google itself. I would like a datePicker to display that date. Here is where I am at.

function testRun()
{
  var ss = SpreadsheetApp.getActive();
  var ui = UiApp.createApplication();
  var controls = ui.createVerticalPanel().setHeight(350).setWidth(350);
  var sheet = ss.getActiveSheet();

//Here I grab a cell's data.  It logs as a date: Sat May 02 00:00:00 GMT-05:00 2015
  var lastDay = sheet.getRange(2, 5).getValue();
  Logger.log(lastDay);

//Here I would like to display a datePicker with the date
  var datePicker = ui.createDatePicker();
  datePicker.setValue(new Date(lastDay));

//datePicker.setvalue(lastDay); also does not work.



  controls.add(datePicker);

To summarize: I can't get this datePicker to display a different day, based on a google sheet cell.

Thanks for the help.

1
Could really use help on this...Any way to bump topics on this site? - Jordando
You didn't use the right tag! Use Google-Apps-Script...I'll edit and ( probably) answer :-) - Serge insas

1 Answers

0
votes

The date picker has a setValue() method so that you should be able to set its value using a normal date object... but is seems to be broken. The dateBox has the same method but it works as expected.

That's one for the issue tracker I'm afraid. (added just now : issue 4282 but UiApp won't be updated anymore so I guess this bug will stay there forever...)

demo code :

function doGet() {
  var app = UiApp.createApplication();
  app.add(app.createDateBox().setValue(new Date(1958,1,19,2,0,0,0)))
  app.add(app.createDatePicker().setValue(new Date(1958,1,19,2,0,0,0)))
  return app;
}

demo app online

enter image description here

In this example I set the date in the script to february 19, 1958 but a date read from a spreadsheet would work as well of course.

PS : this is my birthday date, I know I'm old ;-)