Finalfight40
Active Member
- Joined
- Apr 24, 2018
- Messages
- 273
- Office Version
- 365
- Platform
- Windows
Hi All
I am having a problem with making a script. I am making a script that will delete a row a week after something has been approved.
As of right now i have this which when a dropdown is selected as "YES", another cell gets the current date entered:
This would then be followed by this which i would run once a day or so:
The problem im having is with the section i have highlighted in red.
When i test the following:
The answers i am getting are like 152786.0 when i feel like i should be expecting numbers less than 1 since not even a day has passed.
Any help is appreciated.
I am having a problem with making a script. I am making a script that will delete a row a week after something has been approved.
As of right now i have this which when a dropdown is selected as "YES", another cell gets the current date entered:
Code:
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
if( activeSheet.getName() == "TASKS" ) {
var activeRange = ss.getActiveRange();
var activeRow = activeRange.getRow();
var activeColumn = activeRange.getColumn()
if( activeColumn == 13 && activeRow >= 2 ) {
if ( activeRange.getValue() == "YES" ) {
activeSheet.getRange(activeRow, activeColumn + 1).setValue(new Date());
}
else if( activeRange.getValue() != "YES" ) {
activeSheet.getRange(activeRow, activeColumn + 1).setValue("Not Approved");
}
}
}
};
This would then be followed by this which i would run once a day or so:
Code:
function isValidDate(d) {
if ( Object.prototype.toString.call(d) !== "[object Date]" )
return false;
return !isNaN(d.getTime());
}
function DeleteEditorialRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var taskSheet = ss.getSheetByName("TASKS");
var lastRow = taskSheet.getLastRow();
var formattedDate = Utilities.formatDate(new Date(), "GMT", "MM-dd-yyyy");
for (var i = lastRow; i >= 2; i--){
if (taskSheet.getRange(i, 13).getDisplayValue() == "YES"){
if (taskSheet.getRange(i, 12).getDisplayValue() == "YES"){
if([COLOR=#ff0000](new Date() - taskSheet.getRange(i, 14).getValue()) >= 7[/COLOR] && isValidDate(taskSheet.getRange(i, 14).getValue())){
taskSheet.deleteRows(i);
}
}
}
}
};
The problem im having is with the section i have highlighted in red.
When i test the following:
Code:
Logger.log(new Date() - taskSheet.getRange(i, 14).getValue());
The answers i am getting are like 152786.0 when i feel like i should be expecting numbers less than 1 since not even a day has passed.
Any help is appreciated.
Last edited: