Answer the question
In order to leave comments, you need to log in
How, when creating a new row in a table, to fill the 3rd column of this row with the current date?
I need to keep track of the creation date of new lines in a document, how can I implement this using a script? When creating a new row in the table, it is necessary to fill in the 3rd column of this row with the current date. I wanted to do it myself, but I did not find the line creation event tracking in the api.
Answer the question
In order to leave comments, you need to log in
You can enter a timestamp in this column:
function onEdit(event) {
//SETTINGS
var tsheet = 'Sheet'; //лист на котором ты мониторишь изменения
var lcol = 1; //номер самого левого столбца, на котором проверяются изменения; A=1, B=2 и т.д.
var rcol = 2; //номер крайнего правого столбца для проверки
var tcol = 3; //номер колонки, в которой ты хочешь установить штамп со временем
//
var s = event.source.getActiveSheet();
var sname = s.getName();
if (sname == tsheet) {
var r = event.source.getActiveRange();
var scol = r.getColumn();
if (scol >= lcol && scol <= rcol) {
s.getRange(r.getRow(), tcol).setValue(new Date().toLocaleDateString());
}
}
}
Look at onEdit(e) https://developers.google.com/apps-script/guides/t...
When editing a table, you can get the cell number.
But onEdit is suitable if a person edits the table.
There is no such event.
And in general, the event model of Tables is a so-so system. There are two triggers: for the EDIT event and for the CHANGE event. When a new row is added, the CHANGE event will be fired. You can intercept it with the appropriate trigger. Which, unfortunately, will not return anything particularly clever. Unless you handle this event in its entirety:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question