I have a script which is working fine. But I'm looking for some improvement. In column H I have a date (start date for some event) in column K i have dropdown menu with some statuses. The script runs once per day and it checks the date in column H and if it's tomorrow it puts "Planned ENG" status in column K. The improvements I'm trying to add are:
- Comparing dates: currently the date in "H" must be in format dd:mm:yy hh:mm:ss (14/08/2019 01:00:00). The dates are filled by another script and most of the times are in this format. But sometimes we (a lot of co-workers) need to add the date manually and if it's only dd:mm:yy or it's 14/08/2019 00:00:00 the script not working. Can I compare only dd:mm:yy format?
- This will be little harder. I need if the date in column H is Monday the value of H to be changed in Friday.
I have tried:
- change toLocaleDateString() to toDateString() but it returns error:
"TypeError: Cannot find function toDateString in object . (line 18, file "plannedENG")"
- Here I just think that I have to use getDay function but I'm not sure how.
function defaultValue() {
var eng_status ='Planned ENG';
var prop = new properties();
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate()+1);
// Logger.log(tomorrow.toLocaleDateString());
Logger.log(tomorrow.toLocaleDateString());
for (var key in prop.enabledSheetNames) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(prop.enabledSheetNames[key]);
var data = ss.getRange(1, 1, ss.getLastRow(), ss.getLastColumn()).getValues();
for (var i = 0; i < data.length; i++) {
// Logger.log(data[i][4].toString());
var indexOfReqID = data[i][4].toString().indexOf("REQ-SF");
if (indexOfReqID > -1) {
// Logger.log('It is in sheet:' + prop.enabledSheetNames[key]);
// Logger.log('It is in row:' + (i+1));
// Logger.log(data[i][7].toLocaleDateString());
if (data[i][7].toLocaleDateString() == tomorrow.toLocaleDateString() && data[i][10] == '') {
// Logger.log('OK');
ss.getRange((i+1), 11).setValue(eng_status);
}
}
}
}
}