问题
I have the following OnEdit script in a Google spreadsheet that inserts a timestamp when a checkbox is edited. The action is preformed when I make the edit, but does not work when the edit is made by another user. Any help is appreciated.
function onEdit(e) {
addTimestamp(e);
}
function addTimestamp(e){
//variables
var startRow = 3;
var targetColumn = 6;
var ws = "MasterList";
//get modified row and column
var row = e.range.getRow();
var col = e. range.getColumn();
if(col === targetColumn && row >= startRow && e.source.getActiveSheet().getName() === ws){
e.source.getActiveSheet().getRange(row,19).setValue(new Date());
}
}
回答1:
I have seen several cases having problems using chaining with active methods that might be difficult to reproduce.
Try replacing
e.source.getActiveSheet().getName()
by
e.range.getSheet().getName()
Related
- Why Class Range getValues sometimes returns [[]] when chained to Class Sheet getActiveRange?
回答2:
The onEdit() function will run whenever the spreadsheet is edited. And you can check any failures under Tools > Script editor > View > Executions.
The reason that it fails to work under shared users editing is those users do not have permission to edit the target cell. It means you had set the protection of the cell.
来源:https://stackoverflow.com/questions/63398087/onedit-function-not-working-for-shared-users