I am trying to add another line of code to this code to get the 'green' cells to switch back to 'yellow' after a given amount of time. would I add another function or add another else statement? Is it possible to nest the utilities.sleep function in one more time and only trigger it if a greater than condition is met?
In addition if I wanted this to go across rather than columns and pinpoint specific cells that represent tables. Think of a hostess with her seating chart could this be done in the offset clause for rows. and could this code also be run on another sheet and just show the checkboxes to the hostess while the color change and time stamp are run on another sheet?
Right now I have created a time stamp that only satisfies 2 conditions. Un clicked go to green and clicked go to red after a certain amount of time. If I need to create another function who would I run both functions or do I just add more var to the current function to include satisfying my 3rd condition of green to yellow showing a stag-net table ready to be seating while red is showing they have been at the table a long time but its still occupied
function onEdit(e) {
var s = SpreadsheetApp.getActiveSheet(); // the active sheet (no need to check if the sheet == sheet1 as the active sheet will always be the one that's being edited)
var r = e.range; // the range of the edited cell
var c = r.getColumn(); // the column of the range
var timeDelay = 5; // number in seconds
var checkbox = r.getValue(); // the value of the checkbox after being
edited
var date = new Date(); // the date for the timestamp
if (c == 3 && checkbox === true) { // if the checkbox has been checked,
change the color to red
var nextCell = r.offset(0,1);
Utilities.sleep(timeDelay * 100); // Utilities.sleep takes a number in
milliseconds
nextCell.setValue(date).setBackground("red");
} else if (c == 3 && checkbox === false){ // unchecked switch to green
var nextCell = r.offset(0,1);
nextCell.setValue(date).setBackground("green");
Utilities.sleep(timeDelay * 1);
}
}
any time I try to add another else statement I can not and if I add another condition to the green else if to get it to turn to yellow after x amount of minutes it skips go to green and goes right to yellow instead of vacillating between the two
Aucun commentaire:
Enregistrer un commentaire