I am writing a check-in and check-out system so people can sign out gear using Google sheet.
check out function - gets the username and email and protects the cells, disables the checkout button until check in function runs
check in - clears content and (will remove protection) and re-enable checkout button
const ss = SpreadsheetApp.getActiveSpreadsheet();
const table = ss.getSheetByName("table")
var cue = Session.getActiveUser().getEmail()
// 1 row , 4 column
table.getRange(5, 4).setValue(cue);
Logger.log(cue)
var userName = Session.getEffectiveUser().getUsername()
Logger.log(userName)
table.getRange(5, 3).setValue(userName);
var range = table.getRange('C5:F5');
var protection = range.protect().setDescription('Sample protected range');
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
const drawings = table.getDrawings();
const button = drawings.find(drawing => drawing.getOnAction() == "checkout");
button.setOnAction("1");
}
function checkin() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const table = ss.getSheetByName("table")
var range = table.getRange('C5:F5');
range.clearContent();
const drawings = table.getDrawings();
const button = drawings.find(drawing => drawing.getOnAction() == "1");
button.setOnAction("checkout");
}