I have a uiApp that is creating table views from spreadsheet data, but I’m having difficulty with empty cells in a date column.
Basically, some of the spreadsheet cells are optional, and I haven’t figured out how to put no (or a null) value into the table. Right now it works if I set the column value to:
projectDataRaw[i][projectDataKeys[j]]= new Date(); // inserting dummy data
But I want to leave those cells blank in the table view too, however, when I use:
projectDataRaw[i][projectDataKeys[j]]= null; //
Or some variation of that, it errors because the column type is set to DATE.
I could convert to strings, but I kind of wanted to be able to compare date values to each other when they are available.
— Example of issue with table view and null data —
// load data from sheet
var _PMsheet = "sheet key";
var sSheet = SpreadsheetApp.openById(_PMsheet);
var projectData = sSheet.getRangeByName("ProjectDateCol").getValues();
var projectDataTable = Charts.newDataTable();
projectDataTable.addColumn(Charts.ColumnType.DATE, "Date Column");
for (var i=0; i < projectData.length; i++) {
if (projectData[i] == undefined || projectData[i] == "undefined") {
projectDataTable.addRow([null]);// Object type does not match column type.
// null fails, "undefined" fails, "" fails, [] fails
}
else {
projectDataTable.addRow([projectData[i]]); // this cell has a valid date obj
}
}
I created a simple script which writes null to the A1 cell and current date to the A2 cell. The complete column A is validated to be a date time. After the script execution the cell A1 is empty even if it contained a value before and there is no any warning or error message.
If this example does not help you, please publish as smallest as possible working script which does not work as you expected.
Update, basing on the author clarification: I wrote a simple script trying to find the problem cause and to find a workaround. The code is bellow. If to uncomment the
data.addRow(['', 2.0]);line, then an exception thrown by theaddRowmethod. It is an expected behavior. If to uncomment thedata.addRow([null, 3.0]);line, then thechart.setDataTable(data)line throws an exception. This behavior is not correct, from my point of view, and I think it is necessary to report an issue to the issue tracker.Also there is a workaround of this problem by using the DataTableBuilder.setValue method. The code demonstrates it.
By the way, the
DataTableBuilder.setValuedescription in the documentation is not correct. It does not contain thecolumnparameter. It is a topic to the issue tracker.