Hello,
I am attempting to combine two scripts to work in Google Sheets and appreciate any help. Both scripts work independently to enter timestamps but I do not know enough about Javascript to combine them. The screenshot below describes what I attempting to do and the scripts are further below:
—CHECKOUT DATE SCRIPT—
function onEdit(e) {
var row = e.range.getRow();
var col = e.range.getColumn();
var currentDate = new Date();
if(col === 1 && e.source.getActiveSheet().getName() === “Loans” ){
var currentDate = new Date();
if(e.source.getActiveSheet().getRange(row,11).getValue() == ""){
e.source.getActiveSheet().getRange(row,11).setValue(currentDate);
}
}
}
—CHECKIN DATE SCRIPT—
function onEdit(e) {
var { range, value } = e;
var s = range.getSheet();
if (s.getName() == “Loans” && range.columnStart == 9) {
var r = range.offset(0, 1);
if (value == ‘In’) {
r.setValue(new Date()).setNumberFormat(‘mm"/“dd”/“yy” “HH”:“mm”:"ss’);
} else {
r.clearContent();
}
}
}
yamadapanda THANK YOU!!! That worked. I really appreciate your help and this forum!
I hit another bump and would appreciate your help again. The script you provided previously as working well. However apparently the other script I was attempting to use to populate dates on the asset tab no longer work.
The script below seems to work in the absence of other scripts. However, I am still having trouble combining scripts. Your thoughts are very much appreciated!
//Script to populate date on the Asset tab that no longer works when the scripts for the Loans tab is present.
function onEdit(e) {
var row = e.range.getRow();
var col = e.range.getColumn();
var currentDate = new Date();
if(col === 1 && e.source.getActiveSheet().getName() === “Assets” ){
var currentDate = new Date();
if(e.source.getActiveSheet().getRange(row,22).getValue() == ""){
e.source.getActiveSheet().getRange(row,22).setValue(currentDate);
}
}
}
Script for Loans tab that is working
function onEdit(e) {
var row = e.range.getRow();
var col = e.range.getColumn();
var currentDate = new Date();
var s = e.source.getActiveSheet();
if (s.getName() === “Loans”) {
if (col === 1 && s.getRange(row, 11).getValue() === “”) {
s.getRange(row, 11).setValue(currentDate);
} else if (col === 9) {
var r = e.range.offset(0, 1);
if (e.value == “In”) {
r.setValue(currentDate).setNumberFormat(‘mm"/“dd”/“yy” “HH”:“mm”:"ss’);
} else {
r.clearContent();
}
}
}
}