I'm making a property asset management database. I have a Units sheet which allows me to view and edit unit/tenant information. A function called Unit_SaveUpdate()
saves any changes in my database on another sheet.
I originally assigned Unit_SaveUpdate()
to a drawing of a button but abandoned this method because if the User is editing a cell and presses the button before hitting "Enter" on the edited cell, it does not update the database. It's also not mobile compatible.
In its place, I used the checkbox method described by @TheMaster here via an installable onEdit trigger.
It turns out I'm having the exact same problem as before. If I hit "Enter" on the cell I'm editing before I click the "Save/Update" checkbox, it works perfectly. However, if I don't hit "Enter" on the cell I'm editing, and then click the "Save/Update" checkbox, nothing happens. The code doesn't execute at all. Please see code and two videos demonstrating the problem below.
I thought the checkbox method was supposed to address this exact issue. Can anyone figure out what I'm doing wrong? Thank you!
Example 1: Function Fires if User Hits "Enter" Before Checking Box:
<iframe class="embeddedObject shadow resizable" name="embedded_content" scrolling="no" frameborder="0" type="text/html"
style="overflow:hidden;" src="https://www.screencast.com/users/KimHopkins2598/folders/Capture/media/14cb741f-2fbb-4157-ba47-c09a7e508839/embed" height="340" width="1426" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
Example 2: Function Does NOT Fire if User Does NOT Hit "Enter" Before Checking Box:
<!-- copy and paste. Modify height and width if desired. -->
<iframe class="embeddedObject shadow resizable" name="embedded_content" scrolling="no" frameborder="0" type="text/html"
style="overflow:hidden;" src="https://www.screencast.com/users/KimHopkins2598/folders/Capture/media/3ce7b5af-b600-4f3f-8044-abe63119769e/embed" height="334" width="1420" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
Code:
function installedonEdit(event){
var app = SpreadsheetApp;
var activeSheet = app.getActiveSpreadsheet();
var sheet = event.source.getActiveSheet().getName();
var editedCell = event.range.getSheet().getActiveCell();
if(sheet == "Units"){
var sheetUnits = activeSheet.getSheetByName('Units');
const rg = event.range;
const rangeA1 = rg.getA1Notation();
//Button to Save/Update
var SaveUpdateA1 = sheetUnits.getRange('O8').getA1Notation(); //A1 notation of Save/Update button
if(rangeA1 === SaveUpdateA1 && rg.isChecked()){
//sheetUnits.getRange('P2').setValue("Wow");
Unit_SaveUpdate();
rg.uncheck();
}
}
}