Reputation: 43
This is likely a simple problem, but I am new to using google apps scripts. I am trying to write a function that tells me the last time a specific cell within a different sheet than the active one was updated.
The codes I have tried are:
function lastEdit(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Sheet1');
var lastUpdated = s.LastUpdated();
s.getRange('A2').return(lastUpdated);
}
and
function lastEdit(input) {
r = Date(input)
return(r)
}
The first one kicks up an error that .LastUpdated() is not a function and the second only gives me the current Date/Time. Thanks for any help.
Upvotes: 0
Views: 3918
Reputation: 26796
LastUpdated()
As a workaround, you can
Sample:
const ss = SpreadsheetApp.getActiveSpreadsheet()
const s = ss.getSheetByName('Sheet1')
const updatedCellNotation = "A1"
const props = PropertiesService.getScriptProperties()
function lastEdit(){
var lastUpdated = props.getProperty("lastDate")
s.getRange('A2').setValue(JSON.parse(lastUpdated))
}
function onEdit(e){
var editedCell = e.range.getA1Notation()
if(editedCell == updatedCellNotation && e.range.getSheet().getName() == s.getName()){
props.setProperty("lastDate", JSON.stringify(new Date()))
}
}
return
is not a valid method for itUpvotes: 1