You are pretty close, and just need to check the value in code before setting it:
function onEdit(e) {
var col = e.range.getColumn();
// check Ax for any truthy value
if (e.range.offset(0, 1 - col).getValue()) {
e.range.offset(0, 5 - col, 1, 1).setValue("ready");
}
}
Note that the above requires no trigger, as it meets the qualification for the simple trigger, onEdit
.
If your intent is to bind to the on form submit
trigger, you'll need to name it something else (e.g. function addStatus(e)
), and install the trigger for it. Note that in general, column A has the timestamp of the submission, and thus you do not need to check it for a value. Rather, if your goal is to simply add "ready" to the column next to the just-added form:
function addReady(e) {
var numQs = e.range.getNumColumns();
e.range.offset(0, numQs, 1, 1).setValue("ready");
}
Range offsets are always relative to the upper left cell, so offseting the number of questions and reducing the selection to a single row and column gives us the cell in the same row, adjacent to the questions.
.offset
from aRange
, avoiding the need to backpedal to the sheet and callgetRange
again. – tehhowch